存在许多UI更新的情况,因为大量的InotifyChangEdProperties事件。在这种情况下,您可能希望只有在批处理中设置的所有属性都有一次时才向UI发出更改。

我发现这篇伟大的文章介绍了如何推迟viewCollection的刷新:

http://marlongrech.wordpress.com/2008/11//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