I have a collection which is appearing in 2 separate lists. One list should show all the items (unfiltered) and the second list should show the items which match a certain criterion (filtered).
The 2 list’s ItemsSource Properties are bound to 2 Properties in the ViewModel.
I tried to set a DefaultView for the filtered list but it affects both lists.
ListCollectionView view = (ListCollectionView) CollectionViewSource.GetDefaultView(_manager.Modules);
view.Filter = delegate(object item)
{
Model.BaseModule bm = item as Model.BaseModule;
if (bm != null)
{
return bm is TemplatedUnitOfTest && ((TemplatedUnitOfTest)bm).TemplateGuid == _uot.Header.Id;
}
return false;
};
How should I do this?
Instead of changinge the default view, explicitly create two separate instances of
ListCollectionView, filter one, and bind each list to the relevant view.An
ItemsControl(or derivative) will always wrap itsItemscollection in aCollectionViewbefore displaying anyway – if you do this step yourself then you have more control over what’s displayed.