CollectionView.DeferRefresh () exception

There are times when you have many UI updates due to the large number of INotifyChangedProperties events. In this case, you may need to signal changes in the user interface only once, when all the properties are set as in a package.

I found this wonderful article that explains how to defer a ViewCollection update:

http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/

However, I get an exception when the View is delayed, and I'm trying to add something to the collection. I do not understand why this should not be allowed. This is all in the first place.

InvalidOperationException: Unable to change or check the contents or current position of the CollectionView while Refresh is deferred.

Does anyone know how to solve this problem? Many thanks,

+7
source share
2 answers

Yes, do not modify the collection of interest. I think you misunderstand the purpose of viewing the collection. This is what MSDN says:

You can present the collection view as a layer on top of the collection binding source, which allows you to navigate and display the collection based on sort, filter and group queries, all without having to manipulate the main source collection .

In short, do not delay the update until you add and delete, otherwise you will manipulate your collection.

+2
source

I think you misunderstand or misrepresent MSDN help on this. They say that you do not need to modify the base collection for sorting or filtering. They do not say that you cannot change the base collection. OP has a very valid point. We have a large collection that has been sorted and filtered for the user, and it appears in the list. When the user selects the range of these records and wants to delete them, we are forced into a situation where the ListCollectionView updates the view for each item that has been deleted.

I think the OP question is very important. Performance is terrifying because we have several filters on a huge dataset. DeferRefresh has a real purpose in a class such as ListCollectionView, but with an inexplicable disconnect to insert and delete when you need it most.

+14
source

Source: https://habr.com/ru/post/888325/


All Articles