发生此问题的是,每当更改WPF ComboBox
ItemsSource属性时,SelectedItem属性都将设置为null .
Requirements to recreate issue:
-
Original ItemsSource是非值类型的对象的集合
-
SelectedValue绑定到某个属性
-
已设置SelectedValuePath
-
SelectedItem是原始ItemsSource中的一些项目
-
New ItemsSource是与原始对象类型相同的对象的集合
-
ItemsSource,它不包含对当前SelectedItem中内存中相同对象的引用
其实我想在Datagrid模板中绑定Combobox,在视图模型中存在Combobox集合,当我更改第一列属性时,其他行组合框项目变为null .
How can i solve this issue?
1 回答
SelectedItem对象必须位于ItemsSource集合中 .
如果要从新的ItemsSource集合中分配新的SelectedItem,该集合与先前SelectedItem上的属性匹配,则在更改ItemsSource之前保存属性值并找到匹配的项目 .