WPF Multiple CollectionView with different filters on same collection

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.


For anyone struggling with the problem that the filteredView does not observe the sourceCollection (messageList in this example):

I came around with this solution:

ICollectionView filteredView = new CollectionViewSource { Source=messageList }.View;
messageList.CollectionChanged += delegate { filteredView.Refresh(); };

So it will refresh our filteredView evertytime the CollectionChanged event of the source get's fired. Of course you can implement it like this too:

messageList.CollectionChanged += messageList_CollectionChanged;

private void messageList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
    filteredView.Refresh(); 
}

Consider using PropertyChanged-Events when filtering on a specific Property is wanted.