且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF - 组合框的SelectedItem没有得到设置?

更新时间:2023-10-03 12:17:28

如果所选的项目不包含在该列表中的同一个实例,您必须覆盖在CustomObject的equals(),以便让组合框知道它是同一个对象。

If the item that is selected is not the same instance that is contained in the List, you must override Equals() in the CustomObject to let the ComboBox know that it is the same object.

如果这是相同的情况下,也许这只是一个简单的事情,如BindingMode设置为双向:

If it's the same instance, maybe it's only a simple thing such as setting the BindingMode to TwoWay:

SelectedItem="{Binding Path=CustomSettingProperty,Mode=TwoWay}"