我正在尝试使用 WPF。我正在尝试将用户定义的类ComboBox与List<MyClass>where绑定。MyClass我想设置SelectedValuePathComboBox 的属性,以便 ComboBox 项的值代表MyClass.
我尝试将SelectedValuePath属性设置为.and 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 = "????";