2017-05-16 61 views
-2

我試圖做的組合框,可以顯示一些2類, - 員工 - 僱主 顯然,這兩個類有一個可編輯變量C#做的ObservableCollection <T>在Tamplate

private ObservableCollection<Employer> _itemsEmployer 
    private ObservableCollection<Employee> _itemsEmployee 
    public ObservableCollection<T> Items, where T : Employee, Employer 
    { 
     get 
     { 
      return _itemsEmployee; 
     } 

     set 
     { 
      if (_itemsEmployee == value) 
      { 
       return; 
      } 

      _itemsEmployee = value; 
     } 
    } 

組合框:

<ComboBox x:Name="cbx" 
         IsTextSearchEnabled="True" 
         TextSearch.Text="EditAble" 
         ItemsSource="{Binding Items}" IsEditable="True" 
         DisplayMemberPath="EditAble" 
         Text="{Binding AddedText,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" 
         Canvas.Left="78" Canvas.Top="48" Width="259"> 
+3

你的問題是什麼? – niksofteng

回答

0

屬性無法定義通用約束。您需要擁有Employee和Employer的基類 - 例如人。這種方式收集可以同時僱員和僱主。

private ObservableCollection<Person> _persons = new ObservableCollection<Person>(); 

public ObservableCollection<Person> Items 
{ 
    get 
    { 
     return _persons; 
    } 

    set 
    { 
     if (value == _persons) 
     { 
      return; 
     } 

     _persons = value; 
    } 
} 
相關問題