我正在使用後端類中的2個列表。每個列表都是不同的類型。想要向用戶呈現單個列表(包含兩個列表的聯合),其中當該列表中的項目被選擇時,該項目的細節出現。WPF合併項目源列表
的代碼看起來是這樣的:
我的後端類看起來有些事情是這樣
public ObservableCollection<Person> People {get;}
public ObservableCollection<Product> Products {get;}
我的XAML看起來像這樣
<ListBox x:Name="TheListBox" ItemsSource={Some Expression to merge People and Products}>
<ListBox.Resources>
People and Product Data Templates
</ListBox.Resources>
</ListBox>
...
<ContentControl Content={Binding ElementName=TheListBox, Path=SelectedItem }>
<ContentControl.Resources>
Data Templates for showing People and Product details
</ContentControl.Resources>
</ContentControl>
有什麼建議?
我正在尋找類似的東西,我可以直接使用標記,並且不污染我的視圖模型界面。它應該基本上解決視圖模型提供的項目之間的不匹配問題,這可能是多個集合或幾個獨立的屬性,以及WPF所期望的,這是一個單一的枚舉。理想情況下,我甚至想直接在標記中添加項目,這甚至不對應於視圖模型中的任何內容,但合併到同一個列表中。 – Christo 2011-02-14 07:26:41