I have 3 cascading ICollectionView
s in my view model where one relies on the other.
The first one, isn't bound to a control on the view but is rather used as a key-filter for the two upcoming ones that are displayed to user as master-detail.
My problem is, I attached a filter predicate to the main collection-view, but when I call Refresh
from it, it doesn't go to the filter at all. I even tried throwing an exception from the filter predicate so in case the debugger cannot reach that code I will still see it arrived, but no exception was thrown.
What can be the reason that I call Refresh and it doesn't take me to the filter predicate - meaning it's not recreating the view?
I found a workaround that works, but I don't like it.
What I'm doing is resetting the Filter
property again, that does the job.
I wandered around a bit in Reflector trying to find what am I missing but didn't have great success clarifying what's the quirk.
private ICollectionView _Products;
public ICollectionView Products
{
get
{
if (_Products == null)
{
_Products =
CollectionViewSource.GetDefaultView(ProductsLibrary.SupportedProducts);
_Products.Filter = product => FilterProduct((Product)product);
}
return _Products;
}
}
private bool FilterProduct(Product product)
{
/**********************/
}
////////////////////
private void Search()
{
//Products.Refresh();
Products.Filter = product => FilterProduct((Product)product);
Categories.Refresh();
CategoryProducts.Refresh();
}
I've found a much simpler solution.
I changed the first ICollectionView
to a simple IEnumerable<Product>
, returning a Linq query.
Without finding out why the refresh didn't work, however on the other collection views (that are bound to the UI) the refresh does work, and so, the linq filter of the IEnumerable<Product>
does the job.