-2
<ComboBox Grid.Row="0" ItemsSource="{Binding Path=optList}" IsSynchronizedWithCurrentItem="False" />
<ComboBox Grid.Row="1" ItemsSource="{Binding Path=optList}" IsSynchronizedWithCurrentItem="False" />
public ObservableCollection<ComboBoxItem> optList{ get; set; } = new ObservableCollection<ComboBoxItem>() {
new ComboBoxItem() { Content = "1"},
new ComboBoxItem() { Content = "2"}
}
当我在组合框之间切换时,一个下拉列表变为空。你知道为什么吗?它正在处理String的集合。两个组合框具有相同的ItemsSource of ObservableCollection <ComboBoxItem>
不要这样做,'ComboBoxItem'的'ObservableCollection'很丑。请阅读有关MVVM的更多信息,以及如何从模型中分离视图。要解决您的错误:请改为使用“ObservableCollection”。 –
dymanoid
我用ObservableCollection它工作良好 –
user3046935