相同的ItemSource,但是每个列表框都有另一个View
本文关键字:列表 View 另一个 ItemSource | 更新日期: 2023-09-27 18:08:05
我的情况如下:
存在一个ObservableCollection,并且在一个窗口中有一系列的列表框显示它们的绑定数据。
public Records myRecents;
//...
this.lbToday.ItemsSource = myRecents;
this.lbYesterday.ItemsSource = myRecents;
this.lbBefore2Days.ItemsSource = myRecents;
this.lbLast7Days.ItemsSource = myRecents;
this.lbLast30Days.ItemsSource = myRecents;
现在,我想把每个列表框应用到不同的过滤视图。
this.lbToday.Items.Filter = delegate(object item)
{
return ((RecordItem)item).IsToday();
};
问题是,过滤器应用了所有使用相同itemsource的列表框。(在这种情况下,myRecents)
如何在每个列表框中应用不同的过滤器?
为每个listbox使用不同的ListCollectionViews
this.lbToday.ItemsSource = new ListCollectionView(myRecents);
this.lbYesterday.ItemsSource = new ListCollectionView(myRecents);
this.lbBefore2Days.ItemsSource = new ListCollectionView(myRecents);
this.lbLast7Days.ItemsSource = new ListCollectionView(myRecents);
this.lbLast30Days.ItemsSource = new ListCollectionView(myRecents);