我有一个主从细节场景,我有一个ComboBox列出来自ObjectDataSourceProvider的公司。在那下我有2个ComboBoxes绑定到当前Company对象的Contacts属性。我需要能够在每个ComboBox中选择不同的联系人;但是,只要我在一个列表中更改选择,另一个列表就会更新到同一个联系人。

我尝试了不同的设置(OneWay vs. 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 &QUOT;属性为“False”。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top