将2个WPF ComboBoxes绑定到1个源,而无需"链接"
时间:2020-03-06 14:44:15 来源:igfitidea点击:
我有一个主从场景,其中有一个来自ObjectDataSourceProvider的1个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>
我以为创建CollectionViewSource是一种方法,但是我无法做到这一点。有没有简单的方法可以做到这一点,从而使PrimaryContact和AdminContact不链接?
解决方案
将" IsSynchronizedWithCurrentItem"属性更改为" False"。