Lei Yang
Lei Yang

Reputation: 4335

When is CollectionViewSource.Filter event raised in WPF?

I have some experience of using CollectionViewSource, and can implement sorting, grouping, and filtering with MVVM pattern. But I am curious when is CollectionViewSource.Filter event raised. My usual way is like MSDN, but this is only registering the event, unlike Button.Click I don't see any where to raise this event, such as by keyboard or mouse. So could anyone explain it? Thanks!

Upvotes: 0

Views: 2144

Answers (1)

Frank
Frank

Reputation: 4481

  1. It will be called whenever the collection changes.
  2. You can reevaluate the filter manually if your filter's criteria changes by calling ICollectionView.Refresh in your view model code:

    collectionViewSource.View.Refresh();
    
  3. You can prevent calling the filter repeatedly when you're doing batch modifications:

    using (collectionViewSource.DeferRefresh())
    {
        // update your collection in here
    }
    

Upvotes: 4

Related Questions