2013-08-02 66 views
1

如何將選定的值路徑添加到結構/類中的兩個項目?在下面的例子我想補充SelectedValuePath爲Id1的* Id2的WPF Combobox SelectedValuePath?

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; 
} 

回答

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; 
}