.NET NotifyCollectionChangedAction.Remove 不刷新集合
以下方法从我的自定义可观察集合中删除一系列项目:
public void RemoveRange(IList items)
{
foreach (T item in items)
{
this.Remove(item);
}
UpdateProcessingState(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items));
}
NotifyCollectionChanged 的 EventHandler 仅调用 CollectionView.Refresh()。当我这样做时,删除的项目仍然在我的网格中。
但是,如果我一次删除一项并以此引发集合更改事件;
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item)
网格刷新正常。
我错过了什么吗?
TIA。
The following method removes a range of items from my custom observable collection:
public void RemoveRange(IList items)
{
foreach (T item in items)
{
this.Remove(item);
}
UpdateProcessingState(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, items));
}
EventHandler for NotifyCollectionChanged simply calls CollectionView.Refresh(). When I do this, removed items are still in my grid.
However, if I remove one item at a time and raise collection change event with this;
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item)
grid refreshes properly.
Did I miss something?
TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当有多个项目时,CollectionView 无法正确支持 CollectionChanged 事件。我感觉他们没有实现这一点,因为他们也没有将 AddRange/RemoveRange 实现到 ObservableCollection 中。
您可以尝试使用NotificationCollectionChangedAction.Reset。请注意,如果您正在处理巨大的列表,则重置会带来性能成本,因为与集合相关的任何内容都必须重新绑定每个项目。
CollectionView doesn't properly support the CollectionChanged event when there are multiple items. I get the feeling they didn't implement that since they didn't implement AddRange/RemoveRange into ObservableCollection either.
You can try using the NotificationCollectionChangedAction.Reset instead. Just be wary that there's a performance cost with resets if you're working with huge lists, because anything associated with the collection will have to rebind every item.