2016-11-23 48 views
0

は今、私はこれを使用することができComboBoxのDisplayMemberPathを動的に変更しますか?

  <ComboBox ItemsSource="{Binding EmployeeList}" 
         SelectedValue="{Binding SelectedEmployee}" 
         DisplayMemberPath="Project"/> 

...このようにXAMLを通じてそのリストを結合し、その後

public class Employee 
{ 
    private int ID { get; set; } 
    public string Name { get; set; } 
    public string Department { get; set; } 
    public string Project { get; set; } 

} 

...私は、単純なEmployeeオブジェクトのリストをコンボボックスを埋めるためにしたいと言うと、コンボボックスをクリックして[プロジェクト別従業員レコード]を選択します。しかし従業員が現在それらに関連付けられたプロジェクトを持っていない場合は、私が選択した場合、氏名または部署でレコードを検索する機能(同じコンボボックスとバインディングを使用する)も欲しいと思います。私が上記のようにDisplayMemberPath値を変更する何かを実装する方法についてのアイデアはありますか?

答えて

0

DisplayMemberPathはちょうどa string propertyです。あなたのビューモデルでそれにバインドします。

<ComboBox ... 
    DisplayMemberPath="{Binding DispMemberPath}" 
/> 

のViewModel ...

private string _DispMemberPath; 
public string DispMemberPath 
{ 
    get {return _DispMemberPath; } 
    set { _DispMemberPath= value; RaiseNotifyPropertyChanged(); } 
} 

private void SetDepartmentAsPath() 
{ 
    this.DispMemberPath = "Department"; 
} 
関連する問題