2 つの WPF ComboBox を「リンク」せずに 1 つのソースにデータバインドする

StackOverflow https://stackoverflow.com/questions/134872

  •  02-07-2019
  •  | 
  •  

質問

ObjectDataSourceProvider から企業をリストする ComboBox が 1 つあるマスター詳細シナリオがあります。その下には、現在の Company オブジェクトの Contacts プロパティにバインドされている 2 つの ComboBox があります。各コンボボックスで異なる連絡先を選択できる必要があります。ただし、一方のリストの選択を変更するとすぐに、もう一方のリストも同じ連絡先に更新されます。

さまざまな設定を試してみました(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" です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top