xaml
<UserControl x:Class="System.Windows.Controls.Samples.DataFormHeterogeneousDataSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<StackPanel>
<ContentControl Content="DataForm with Heterogeneous Data" />
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<CheckBox Content="AutoCommit" IsChecked="{Binding AutoCommit, ElementName=dataForm, Mode=TwoWay}" Margin="4" />
<CheckBox Content="AutoEdit" IsChecked="{Binding AutoEdit, ElementName=dataForm, Mode=TwoWay}" Margin="4" />
<TextBlock Text="CommandButtonsVisibility" Margin="4" />
<ComboBox SelectedItem="{Binding CommandButtonsVisibility, ElementName=dataForm, Mode=TwoWay}" SelectedIndex="0" Margin="4">
<sys:String>All</sys:String>
<sys:String>Add</sys:String>
<sys:String>Delete</sys:String>
<sys:String>Edit</sys:String>
<sys:String>Navigation</sys:String>
<sys:String>None</sys:String>
</ComboBox>
<CheckBox Content="IsReadOnly" IsChecked="{Binding IsReadOnly, ElementName=dataForm, Mode=TwoWay}" Margin="4" />
</StackPanel>
<dataform:DataForm x:Name="dataForm" Width="350" ItemsSource="{Binding}" HorizontalAlignment="Left" MaxWidth="500" Margin="4" Grid.Column="1" />
</Grid>
</StackPanel>
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<StackPanel>
<ContentControl Content="DataForm with Heterogeneous Data" />
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<CheckBox Content="AutoCommit" IsChecked="{Binding AutoCommit, ElementName=dataForm, Mode=TwoWay}" Margin="4" />
<CheckBox Content="AutoEdit" IsChecked="{Binding AutoEdit, ElementName=dataForm, Mode=TwoWay}" Margin="4" />
<TextBlock Text="CommandButtonsVisibility" Margin="4" />
<ComboBox SelectedItem="{Binding CommandButtonsVisibility, ElementName=dataForm, Mode=TwoWay}" SelectedIndex="0" Margin="4">
<sys:String>All</sys:String>
<sys:String>Add</sys:String>
<sys:String>Delete</sys:String>
<sys:String>Edit</sys:String>
<sys:String>Navigation</sys:String>
<sys:String>None</sys:String>
</ComboBox>
<CheckBox Content="IsReadOnly" IsChecked="{Binding IsReadOnly, ElementName=dataForm, Mode=TwoWay}" Margin="4" />
</StackPanel>
<dataform:DataForm x:Name="dataForm" Width="350" ItemsSource="{Binding}" HorizontalAlignment="Left" MaxWidth="500" Margin="4" Grid.Column="1" />
</Grid>
</StackPanel>
</StackPanel>
</UserControl>
c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace System.Windows.Controls.Samples
{
public partial class DataFormHeterogeneousDataSample : UserControl
{
public DataFormHeterogeneousDataSample()
{
InitializeComponent();
DataContext = PersonData.GetData();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
object o = dataForm.CurrentItem;
}
}
public class PersonData
{
public static ObservableCollection<People> GetData()
{
return new ObservableCollection<People>
{
new People
{
FirstName = "Kim",
LastName = "Abercrombie",
Phone = "(555) 555-0000",
Street1 = "1 Anywhere Street",
City = "Anytown",
State = "WA",
Zip = 12345
},
new People
{
FirstName = "Hadaya",
LastName = "Sagiv",
Phone = "(555) 555-0001",
Street1 = "2 Anywhere Street",
City = "AnotherTown",
State = "HI",
Zip = 55555
},
new People
{
FirstName = "Jeff",
LastName = "Price",
Phone = "(555) 555-0002",
Street1 = "3 Somewhere Street",
City = "Anytown",
State = "OR",
Zip = 77777
},
new People
{
FirstName = "Chris",
LastName = "Hill",
Phone = "(555) 555-0431",
Street1 = "17 Anywhere Lane",
City = "AnotherTown",
State = "WA",
Zip = 28145
}
};
}
}
public class People
{
private string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
private string lastName;
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
private string phone;
public string Phone
{
get { return phone; }
set { phone = value; }
}
private string street1;
public string Street1
{
get { return street1; }
set { street1 = value; }
}
private string street2;
public string Street2
{
get { return street2; }
set { street2 = value; }
}
private string city;
public string City
{
get { return city; }
set { city = value; }
}
private string state;
public string State
{
get { return state; }
set { state = value; }
}
private string email;
public string Email
{
get { return email; }
set { email = value; }
}
private int zip;
public int Zip
{
get { return zip; }
set { zip = value; }
}
private bool isBusinessAddress;
public bool IsBusinessAddress
{
get { return isBusinessAddress; }
set { isBusinessAddress = value; }
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace System.Windows.Controls.Samples
{
public partial class DataFormHeterogeneousDataSample : UserControl
{
public DataFormHeterogeneousDataSample()
{
InitializeComponent();
DataContext = PersonData.GetData();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
object o = dataForm.CurrentItem;
}
}
public class PersonData
{
public static ObservableCollection<People> GetData()
{
return new ObservableCollection<People>
{
new People
{
FirstName = "Kim",
LastName = "Abercrombie",
Phone = "(555) 555-0000",
Street1 = "1 Anywhere Street",
City = "Anytown",
State = "WA",
Zip = 12345
},
new People
{
FirstName = "Hadaya",
LastName = "Sagiv",
Phone = "(555) 555-0001",
Street1 = "2 Anywhere Street",
City = "AnotherTown",
State = "HI",
Zip = 55555
},
new People
{
FirstName = "Jeff",
LastName = "Price",
Phone = "(555) 555-0002",
Street1 = "3 Somewhere Street",
City = "Anytown",
State = "OR",
Zip = 77777
},
new People
{
FirstName = "Chris",
LastName = "Hill",
Phone = "(555) 555-0431",
Street1 = "17 Anywhere Lane",
City = "AnotherTown",
State = "WA",
Zip = 28145
}
};
}
}
public class People
{
private string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
private string lastName;
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
private string phone;
public string Phone
{
get { return phone; }
set { phone = value; }
}
private string street1;
public string Street1
{
get { return street1; }
set { street1 = value; }
}
private string street2;
public string Street2
{
get { return street2; }
set { street2 = value; }
}
private string city;
public string City
{
get { return city; }
set { city = value; }
}
private string state;
public string State
{
get { return state; }
set { state = value; }
}
private string email;
public string Email
{
get { return email; }
set { email = value; }
}
private int zip;
public int Zip
{
get { return zip; }
set { zip = value; }
}
private bool isBusinessAddress;
public bool IsBusinessAddress
{
get { return isBusinessAddress; }
set { isBusinessAddress = value; }
}
}
}