I am trying my hands on WPF. I am trying to bind a ComboBox
with List<MyClass>
where MyClass
is user defined class. I want to set SelectedValuePath
property of ComboBox so that, value of ComboBox item represents object of MyClass
.
I tried setting SelectedValuePath
property to .
and this
, but no luck. Can anybody suggest me the way to achieve it?
Example Code :
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.