わかりました。あなたがリストを持っていることを正しく理解していればList<Customer>
、リストのリストはComboBoxにバインドされ、各子リストはDataGridにバインドされます。
例:
Xaml:
<Window x:Class="WpfApplication13.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Name="UI">
<Grid DataContext="{Binding ElementName=UI}">
<ComboBox DataContext="{Binding ComboItems}" Height="27" VerticalAlignment="Top" >
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" ColumnWidth="150" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding CustomerName}" />
<DataGridTextColumn Header="Address" Binding="{Binding BillingAddress}" />
</DataGrid.Columns>
</DataGrid>
</ComboBox>
</Grid>
</Window>
コード:
public partial class MainWindow : Window, INotifyPropertyChanged
{
private ObservableCollection<Customer> _comboItems = new ObservableCollection<Customer>();
public MainWindow()
{
InitializeComponent();
ComboItems.Add(new Customer { CustomerName = "Steve", BillingAddress = "Address" });
ComboItems.Add(new Customer { CustomerName = "James", BillingAddress = "Address" });
}
public ObservableCollection<Customer> ComboItems
{
get { return _comboItems; }
set { _comboItems = value; }
}
}
public class Customer : INotifyPropertyChanged
{
private string _customerName;
private string _billingAddress;
public string CustomerName
{
get { return _customerName; }
set { _customerName = value; RaisePropertyChanged("CustomerName"); }
}
public string BillingAddress
{
get { return _billingAddress; }
set { _billingAddress = value; RaisePropertyChanged("BillingAddress"); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
結果: