2011-10-21 36 views
0

我有以下数据结构中:的DataGrid的ItemSource势必选定项的另一数据网格

List<Customer> currentCustomers {...} 

public class Customer 
{ 
    public string ID { get, set } 
    public string Name { get, set } 
    [...] 
    public List<Products> { get, set } 
} 

我有一个绑定到currentCustomers列表中的客户数据网格。 我想要做的是将第二个DataGrid绑定到客户中选定的项目,以显示该客户的所有产品信息。

即用户点击客户DataGrid中的客户,然后基于该客户产品自动更新第二个DataGrid。

这甚至可能吗?

如果是这样,是否有资源会告诉/告诉我这是如何完成的?

回答

2

它只是绑定到SelectedItem属性:

<DataGrid x:Name="customersList" CanSelectMultipleItems="false" ... /> 

<DataGrid x:Name="customerDetails" 
      ItemsSource = "{Binding ElementName = customersList, 
            Path = SelectedItem.Products}"> 
3

这应该工作:

<DataGrid x:Name="one"></DataGrid> 
<DataGrid x:Name="two" DataContext="{Binding ElementName=one, Path=SelectedItem.Products}"></DataGrid> 
相关问题