案例地址:GitHub - microsoft/WPF-Samples: Repository for WPF related samples
一、运行界面
二、案例功能描述
知识点:
1、CompositeCollection 允许将多个集合和项作为一个列表显示
2、CollectionContainer: 保留现有的集合结构,
如System.Collections.ObjectModel.ObservableCollection`1 或 System.Data.DataSet,以在System.Windows.Data.CompositeCollection 中使用。
三、分析代码
1、实现ListBox中的选项多类型的功能
<ListBox Name="myBox" Height="300" Width="200" Background="White">
<ListBox.ItemsSource>
<CompositeCollection>
<CollectionContainer
Collection="{Binding Source={StaticResource GreekGodsData}}" />
<CollectionContainer
Collection="{Binding Source={StaticResource GreekHeroesData}}" />
<ListBoxItem Foreground="Red">Other Listbox Item 1</ListBoxItem>
<ListBoxItem Foreground="Red">Other Listbox Item 2</ListBoxItem>
</CompositeCollection>
</ListBox.ItemsSource>
</ListBox>