Nickolay Kondratyev
Nickolay Kondratyev

Reputation: 5221

When is CollectionView.Refresh() usually required?

I am not familiar at all with using WPF and the application that I am working on had a ListCollectionView.Refresh() every time one of the objects in the ListCollection View Model would change which made the application extremely inefficient (ListCollectionView is binded to List Collection View Model). After removing the Refresh() the application runs a lot smoother and still updates when changes occur in ListCollection View Model. After looking around it seems that any time there is a filter or re-sort on the CollectionView there is an implicit call to Refresh(). So when is it necessary to Refresh() and recreate the CollectionView?

Upvotes: 2

Views: 3343

Answers (2)

Alan Bradbury
Alan Bradbury

Reputation: 140

CollectionView doesn't handle CollectionChanged events where more than one item is changing (an exception occurs); Refresh() can be used instead, which is why you are seeing calls with filters and sorts.

Upvotes: 0

Michael
Michael

Reputation: 9042

If I understand you correctly, you have a ListCollectionView that is bound to a ListCollectionViewModel (your own class). As long as ListCollectionViewModel implements INotifyCollectionChanged properly (eg. it inherits from ObservableCollection<T>), and the items in the collection implement INotifyPropertyChange properly, then it is not necessary to call Refresh().

Upvotes: 3

Related Questions