开发者

Same ItemSource, but has another View each listboxes

开发者 https://www.devze.com 2023-04-04 11:51 出处:网络
Here is my situation: A ObservableCollection is exist and a series of listbox in a window has showing their bound data.

Here is my situation:

A ObservableCollection is exist and a series of listbox in a window has showing their bound data.

public Records myRecents;

//...

this.lbToday.ItemsSource = myRecents;
this.lbYesterday.ItemsSource = myRecents;
this.lbBefore2Days.ItemsSource = myRecents;
this.lbLast7Days.ItemsSource = myRecents;
this.lbLast30Days.ItemsSource = myRecents;

And now, I want to applie each listboxes to different filtered view.

this.lbToday.Items.Filter = delega开发者_StackOverflowte(object item)
{
    return ((RecordItem)item).IsToday();
};

A problem is, the filter applied all listboxes which using same itemsource.(in this case, the 'myRecents')

How can I applying differ filterings each listbox?


Use different ListCollectionViews for each one of your ListBoxes

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); 
0

精彩评论

暂无评论...
验证码 换一张
取 消