pal*_*rse 5 data-binding wpf xaml
我有一个主从场景,其中有1个来自ObjectDataSourceProvider的ComboBox上市公司。在此之下,我有2个ComboBoxes绑定到当前Company对象的Contacts属性。我需要能够在每个组合框中选择其他联系人;但是,一旦我在一个列表中更改选择,其他列表就会更新为同一联系人。
我尝试了不同的设置(OneWay与TwoWay),但到目前为止似乎没有任何效果。这是我的XAML的摘录。
<Page.Resources>
<!-- This is a custom class inheriting from ObjectDataProvider -->
<wg:CustomersDataProvider x:Key="CompanyDataList" />
</Page.Resources>
<Grid>
<!--- other layout XAML removed -->
<ComboBox x:Name="Customer" Width="150"
ItemsSource="{Binding Source={StaticResource CompanyDataList},Path=Companies,Mode=OneWay}"
DisplayMemberPath="Name"
SelectedValuePath="Id"
IsSynchronizedWithCurrentItem="True"
SelectedValue="{Binding Path=Id, Mode=OneWay}"
VerticalAlignment="Bottom" />
<ComboBox x:Name="PrimaryContact" Width="150"
DataContext="{Binding ElementName=Customer,Path=Items,Mode=OneWay}"
ItemsSource="{Binding Path=Contacts,Mode=OneWay}"
DisplayMemberPath="FullName"
SelectedValuePath="Id"
IsSynchronizedWithCurrentItem="True"
SelectedValue="{Binding Path=Id,Mode=OneWay}" />
<ComboBox x:Name="AdminContact" Width="150"
DataContext="{Binding ElementName=OwnerCustomer,Path=Items,Mode=OneWay}"
ItemsSource="{Binding Path=Contacts,Mode=OneWay}"
DisplayMemberPath="FullName"
SelectedValuePath="Id"
IsSynchronizedWithCurrentItem="True"
SelectedValue="{Binding Path=Id,Mode=OneWay}" />
<!--- other layout XAML removed -->
</Grid>
Run Code Online (Sandbox Code Playgroud)
我以为创建CollectionViewSource是可行的方法,但我无法做到这一点。有没有简单的方法可以做到这一点,从而使PrimaryContact和AdminContact不链接?
| 归档时间: |
|
| 查看次数: |
5638 次 |
| 最近记录: |