我正在努力解决可以这样概括的 WPF 问题:
有两个 ListView
<ListView x:Name="listView1"></ListView> <ListView x:Name="listView2"></ListView>
在代码隐藏中为它们创建了过滤器:
var listViewCollection1 = (ListCollectionView)CollectionViewSource.GetDefaultView(Items); listViewCollection1.Filter = item => (item as string).Length == 5; listView1.ItemsSource = listViewCollection1; var listViewCollection2 = (ListCollectionView)CollectionViewSource.GetDefaultView(Items); listViewCollection2.Filter = item => (item as string).Length == 3; listView2.ItemsSource = listViewCollection2; public ObservableCollection<string> items = new ObservableCollection<string>() { "John", "Jan", "Lanny", "Carol", "Hug", }; public ObservableCollection<string> Items { get { return items; } private set { items = value; } }
第二个过滤器覆盖第一个过滤器,以下项目显示在两个列表视图中:
- 简
- 拥抱
谁能告诉我,怎么了?如何正确实例化绑定到一个数据源、具有两个不同过滤器的两个 listView?
我将不胜感激任何帮助。