0

我正在尝试使用 WPF。我正在尝试将用户定义的类ComboBoxList<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 = "????"; 
4

1 回答 1

0

改用cmb.SelectedItem它返回一个对象,将其转换为MyClass并且根本不设置 SelectedValuePath

于 2013-01-23T11:26:11.547 回答