WPF组合框SelectedValuePath?
如何将所选值路径添加到结构/类中的两个项?在下面的示例中,我想将SelectedValuePath添加为Id1*Id2WPF组合框SelectedValuePath?,wpf,combobox,Wpf,Combobox,如何将所选值路径添加到结构/类中的两个项?在下面的示例中,我想将SelectedValuePath添加为Id1*Id2 this.cboXXX.ItemsSource = Employee; this.cboXXX.DisplayMemberPath = "Name"; *this.cboXXX.SelectedValuePath = "Id1" + "*" + "Id2";* ?? public struct Employee { public int Id1; public
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;
}
您不能这样做,因为
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;
}