如何将选定的值路径添加到struct / class中的两个项目?在下面的示例中,我想将SelectedValuePath添加为Id1 * Id2
this.cboXXX.ItemsSource = Employee;
this.cboXXX.DisplayMemberPath = "Name";
*this.cboXXX.SelectedValuePath = "Id1" + "*" + "Id2";* ??
public struct Employee
{
public int Id1;
public int Id2;
public string Name;
}
答案 0 :(得分:2)
您不能因为SelectedValuePath
是对象属性路径。你可以这样做,但是......
this.cboXXX.DisplayMemberPath = "Name";
this.cboXXX.SelectedValuePath = "CombinedID";
public struct Employee
{
public int _Id1;
public int Id1
{
get {return _Id1;}
set
{
_Id1 = value;
CombinedID = Id1 + "*" + Id2;
}
}
public int _Id2;
public int Id2
{
get { return _Id1; }
set
{
_Id1 = value;
CombinedID = Id1 + "*" + Id2;
}
}
public string CombinedID {get;set;}
public string Name;
}