开发者

.NET NotifyCollectionChangedAction.Remove does not refresh collection

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(). W开发者_如何学JAVAhen 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜