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。我根據您的答案實施瞭解決方案,現在它工作得很好。 –