WPF Multiple CollectionView with different filters on same collection

前端 未结 2 1327
遥遥无期
遥遥无期 2020-12-07 17:54

I\'m using a an ObservableCollection with two ICollectionView for different filters.

One is for filtering messages by some type, and one is

2条回答
  •  误落风尘
    2020-12-07 18:03

    This answer helped me with this exact problem. The static CollectionViewSource.GetDefaultView(coll) method will always return the same reference for a given collection, so basing multiple collection views on the same reference will be counterproductive. By instantiating the view as follows:

    ICollectionView filteredView = new CollectionViewSource { Source=messageList }.View;
    

    The view can now be filtered/sorted/grouped independently of any others. Then you can apply your filtering.

    I know it's been a couple months and you have probably solved your problem by now, but I ran across this question when I had the same problem so I figured I would add an answer.

提交回复
热议问题