【发布时间】:2014-12-24 06:38:06
【问题描述】:
我有 2 个ComboBoxes,其ItemsSource 绑定到同一个ObservableCollection:
public ObservableCollection<MyType> MyTypeCollection { get; set; }
我定义了 2 个不同的 SelectedItem 属性,它们又绑定到正确的 ComboBox。
public MyType MySelectedItem1 { get; set; }
public MyType MySelectedItem2 { get; set; }
每当我在 ComboBoxes 之一中选择一个项目时,我的类中定义的两个 SelectedItem 属性都会设置为该选择。 ComboBoxes 也都设置为该值。
这是为什么?
我尝试了几种方法,例如 Mode=OneWay 等,但都不起作用。
这是我的 XAML(针对问题进行了删减):
<ComboBox SelectedItem="{Binding MySelectedItem1}"
ItemsSource="{Binding MyTypeCollection, Mode=OneWay}"/>
<ComboBox SelectedItem="{Binding MySelectedItem2}"
ItemsSource="{Binding MyTypeCollection, Mode=OneWay}"/>
【问题讨论】:
-
您的帖子说您的 Xaml 已“精简”。原始版本是否偶然在组合框中有
IsSynchronizedWithCurrentItem="True"?如果是这样,那是你的问题。 -
@MikeStrobel 是的,他们有,从 XAML 中删除它们解决了这个问题。谢谢!
标签: c# wpf binding combobox itemssource