Rac*_*hel 11 wpf binding combobox selecteditem itemssource
我有一个ComboBox,它的ItemsSource绑定到一个静态List<CustomSettings>的选项.ComboBox是绑定到CustomObject类的表单的一部分,该类的一个属性是CustomSettingProperty.
我想将ComboBox的SelectedItem绑定到CustomObject中指定的属性,但是SelectedItem="{Binding Path=CustomSettingProperty}"没有设置默认的选定项.使用断点我可以看到它正在调用get;方法,所以我认为问题可能在于CustomSettingProperty是单独创建的,List<CustomObject>因此WPF认为它不是同一个项目.
是否有捷径可寻?或者也许是另一种选择,因为CustomSettings类确实包含Id?
Hei*_*z K 22
如果所选项目与List中包含的实例不同,则必须在CustomObject中重写Equals(),以使ComboBox知道它是同一个对象.
如果它是同一个实例,也许只是一个简单的事情,比如将BindingMode设置为TwoWay:
SelectedItem="{Binding Path=CustomSettingProperty,Mode=TwoWay}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10822 次 |
| 最近记录: |