WPF Binding如何导航关系?

时间:2013-06-21 21:31:19

标签: wpf data-binding binding master-detail

我正在尝试以下列方式实现主 - 细节关系:

(shown in a ComboBox)                       (shown in a DataGrid)
|-----------|                               |------------|
| Customers |                               | Orders     |
|-----------|                               |------------|
| Id        |--- CustomersOrdersRelation ---| CustomerId |
| Name      |                               | OrderId    |
| ...       |                               | ...        |
|-----------|                               |------------|

但我也有一个<所有客户>组合框中的项目,我需要查看详细数据网格中显示的所有客户的所有订单。

以下是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}" ...>

现在我有两个问题:

  1. 当组合框的Path=SelectedItem.CustomersOrdersRelation(运行时的DataRowView)没有属性SelectedItem时,数据网格中的绑定如何找到CustomersOrdersRelation

  2. 修改我自己的NullCustomer课程的最简单方法是什么,这样当我选择&lt;所有客户&gt;我会显示AllOrdersCollectionViewSource的结果吗?

1 个答案:

答案 0 :(得分:1)

  1. DataRowView实现ICustomTypeDescriptor,绑定系统可能会使用它来确定如何获取该属性。

  2. 同时为其提供一个属性CustomersOrdersRelation,该属性会为客户的所有订单返回包含CompositeCollection的{​​{1}}。

相关问题