CollectionView.DeferRefresh() 抛出异常
在某些情况下,由于大量 INotifyChangedProperties 事件,您会进行多次 UI 更新。在这种情况下,当所有属性都像批量设置一样时,您可能只想向 UI 发出一次更改信号。
我发现这篇很棒的文章解释了如何推迟 ViewCollection 的刷新:
http: //marlongrech.wordpress.com/2008/11/22/icollectionview-explained/
但是,当视图被延迟并且我尝试添加时,我收到异常收藏一些东西。我不明白为什么不允许这样做。这就是它的全部意义所在。
无效操作异常: 无法更改或检查内容或当前位置 CollectionView 同时刷新被推迟。
有谁知道如何解决这个问题? 非常感谢,
There are cases when you have many UI updates due a massive amount of INotifyChangedProperties events. In that case you might want to signal the changes to UI only once when all the properties are set like in a batch.
I found this great article that explains how to defer the refresh of the ViewCollection:
http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/
However I get an exception when the View is deferred and I try to add something to the collection. I don't understand why this shouldn't be allowed. That's the whole point of it in first place.
InvalidoperationException:
Cannot change or check the contents or Current position of
CollectionView while Refresh is being deferred.
Does anyone know how to solve this problem?
Many Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您误解或歪曲了 MSDN 关于该主题的帮助。他们说您不必修改底层集合即可进行排序或过滤。他们并不是说您不能修改底层集合。 OP 有一个非常有效的观点。我们有一个大型集合,已为用户排序和过滤,并显示在列表框中。当用户选择一系列记录并想要删除它们时,我们被迫陷入这样的情况:ListCollectionView 会刷新每个已删除项目的视图。
我认为OP的问题非常有道理。性能非常糟糕,因为我们对大量数据有多个过滤器。 DeferRefresh 在像 ListCollectionView 这样的类上有真正的用途,但是当您最需要它时,它会莫名其妙地禁用插入和删除。
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.
是的,不要修改有问题的集合。我认为您误解了集合视图的目的。 MSDN 是这么说的;
简而言之,不要推迟刷新,直到完成添加和删除以及对集合的其他操作。
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;
So in short, don't defer the refresh until you are done adding and removing, and otherwise manipulating your collection.