1
我试图实现以下面的方式主从关系:WPF绑定如何导航关系?
(shown in a ComboBox) (shown in a DataGrid)
|-----------| |------------|
| Customers | | Orders |
|-----------| |------------|
| Id |--- CustomersOrdersRelation ---| CustomerId |
| Name | | OrderId |
| ... | | ... |
|-----------| |------------|
但我也有一个<所有客户>项目在ComboBox,为此我需要看到所有客户的所有订单显示在详细数据网格中。
这里是XAML代码片段:
<ComboBox x:Name="CustomersComboBox" ...>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem Content="{StaticResource nullCustomer}" /> <!-- I wrote my own class NullCustomer -->
<CollectionContainer Collection="{Binding Source={StaticResource CustomersCollectionViewSource}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
<DataGrid ItemsSource="{Binding ElementName=CustomersComboBox, Path=SelectedItem.CustomersOrdersRelation}" ...>
现在我有两个问题:
如何在DataGrid中绑定发现
Path=SelectedItem.CustomersOrdersRelation
当组合框的SelectedItem
(这是一个DataRowView在运行时)没有属性CustomersOrdersRelation
?什么是我修改我自己
NullCustomer
类,所以,当我选择<所有客户>我得的AllOrdersCollectionViewSource
显示的结果最简单的方法?
谢谢@ H.B。我根据您的答案实施了解决方案,现在它工作得很好。 –