WPF中CompositeCollection的使用
WPF中CompositeCollection的使用_wpf compositecollection-CSDN博客
注意一点CollectionContainer在绑定vm时,不能直接绑定vm中的对象,需要通过Resources中转,参考以下代码
<MenuItem Width="200" Height="40" VerticalAlignment="Bottom" Background="Black" Header="打开"> <MenuItem.Resources> <CollectionViewSource x:Key="SaveFileHistoryList" Source="{Binding SaveFileHistoryList}" /> </MenuItem.Resources> <MenuItem.ItemsSource> <CompositeCollection> <CollectionContainer Collection="{Binding Source={StaticResource SaveFileHistoryList}}" /> <Separator /> <MenuItem Command="{Binding ClearHistoryCommand}" Header="清除历史记录" /> </CompositeCollection> </MenuItem.ItemsSource> </MenuItem>