CollectionViewSource 方式 在 ListView 或 ListBox 资源里面,添加 CollectionViewSource 绑定到集合里面,然后在 ItemsSource 使用 CompositeCollection 动态绑定 在 ListView 或 ListBox 的资源里面定义了 CompositeCollection 通过控件的 DataContext 绑定多个集合,代码如下 <CompositeCollection = new CompositeCollection(); foreach (var value in values) { if (value is IEnumerable enumerable) { compositeCollection.Add(new (value); } } return compositeCollection; }
Items2Source" Source="{Binding Items2}"/> </ListBox.Resources> <ListBox.ItemsSource> <CompositeCollection Walterlv End Item 1</ListBoxItem> <ListBoxItem>Walterlv End Item 2</ListBoxItem> </CompositeCollection > </ListBox.ItemsSource> </ListBox> 关于 CompositeCollection 的使用示例可以参考: How to: Implement a CompositeCollection