I got really big ObservableCollection<MyItem>
and I need to provide user-friendly filtering on it.
public static async Task RefilterViewAsync(this ItemsControl @this, Predicate<object> compareLogic)
{
await Task.Run(
() =>
{
var collectionView = CollectionViewSource.GetDefaultView(@this.ItemsSource);
if (collectionView.CanFilter)
{
collectionView.Filter = compareLogic;
}
else throw new InvalidOperationException("Filtering not supported...");
collectionView.Refresh();
});
}
..the problem is that the code above doesnt work for some reasons. Fitering on UI-thread takes around 1 minute. Any ideas how to implement async filtering, at least to be able display some "processing.." animation to help user overcome that?
If you have a massive ObservableCollection
and you want to filter it out asynchronously then do it yourself. There is no asynchronous binding support AFAIK.
I mean create another property of type ObservableCollection; this will be your filtered collection. Instead of binding the actual collection, bind the filtered collection to the ItemsControl
.
Then implement your own filtering logic asynchronously(perhaps in another thread) and finally set the filtered collection property. Binding engine will kick up and update the UI accordingly. I've used this successfully in one of my projects earlier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With