Вопрос

Есть случаи, когда у вас есть много обновлений пользовательского интерфейса, из-за массивной суммы событий inotifyChangedProperties.В этом случае вы можете захотете сигнализировать изменения в UI только один раз, когда все свойства устанавливаются, как в пакете.

Я нашел эту отличную статью, которая объясняет, как отложить обновление просмотра ViewCollection:

http://marlongrech.wordpress.com/2008/11/22 / ICOLLECTIONVIEW - объяснено /

Однако я получаю исключение, когда представление отложено, и я пытаюсь добавить что-то в коллекцию.Я не понимаю, почему это не должно быть разрешено.Это вся точка зрения в первую очередь.

InvalidOperationException: Не может изменить или проверять содержимое или текущее положение CollectionView во время обновления отсчитывается.

Кто-нибудь знает, как решить эту проблему? Большое спасибо,

Это было полезно?

Решение

Yes, don't modify the collection in question. I think that you are misunderstanding the purpose of a collection view. This is what MSDN says;

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

So in short, don't defer the refresh until you are done adding and removing, and otherwise manipulating your collection.

Другие советы

I think you are misunderstanding or misrepresenting the MSDN help on the subject. They are saying that you don't have to modify the underlying collection to sort or filter. They are not saying that you can't modify the underlying collection. The OP has a very valid point. We have a large collection that has been sorted and filter for the user and it is displayed in a list box. When the user selects a range of those records and wants to delete them, we are forced into a situation where the ListCollectionView refreshs view for every item that was deleted.

I think the OP's question is very valid. The performance is horrendous because we have multiple filters on a huge set of data. The DeferRefresh has a real purpose on a class like the ListCollectionView, but in inexplicably diabled for inserts and deletes, when you need it the most.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top