![](/img/trans.png)
[英]WPF ComboBox bound with object list and display less different value in selected item than in the item list
[英]Binding ComboBox with Generic List so that value of combobox item represents bound object
我正在尝试使用WPF。 我试图用List<MyClass>
绑定ComboBox
,其中MyClass
是用户定义的类。 我想设置ComboBox的SelectedValuePath
属性,以便ComboBox项的值表示MyClass
对象。
我尝试将SelectedValuePath
属性设置为.
this
,但是没有运气。 有人可以建议我实现这一目标的方法吗?
示例代码:
Class MyClass
{
public int ID {get; set;}
public string Name {get; set;}
}
List<MyClass> lst = new List<MyClass>();
ComboBox cmb = new ComboBox();
cmb.DataContext = lst;
cmb.DisplayMemberPath = "Name";
// Here I want object of MyClass (which is bound to this item) itself should be assigned as value.
cmb.SelectedValuePath = "????";
使用cmb.SelectedItem
代替它返回一个对象,将其cmb.SelectedItem
为MyClass
并且完全不设置SelectedValuePath
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.