Question about NotifyCollectionChangedEventArgs
-
The idea with a collection that implements
INotifyCollectionChanged
, is that it will be (possibly) be used in anItemsControl
, which will get theCollectionViewSource.GetDefaultView(Object)
for it, that is likely to be aListCollectionView
. So far... so good... However, as I just discovered today :-O :omg:, when usingAddRange()
,RemoveRange()
, i.e. creatingAdd/Remove
events with more that 1 object will trigger the following error in theListCollectionView
:System.NotSupportedException: Range actions are not supported.
Stack Trace:
ListCollectionView.ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
AbstractInvocation.Proceed()
Invocation.CallBase() line 147
ReturnBaseOrDefaultValue.Execute(Invocation invocation) line 88
IInterceptor.Intercept(Invocation invocation) line 34
Interceptor.Intercept(IInvocation underlying) line 113
AbstractInvocation.Proceed()
NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)Mmm... unfortunate... :(( I can think of 2 possible fixes and I am undecided as to which one to use?! 1. When a range
Add/Remove
event if fired, instead fire aReset
event. 2. When a rangeAdd/Remove
event if fired, instead fire multipleAdd/Remove
single item events. 3. or.. mmm... have a FireEventMode property, which would let the user decide whether to use event as is, split it, or fire Reset. Wo.. what say you?A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
The idea with a collection that implements
INotifyCollectionChanged
, is that it will be (possibly) be used in anItemsControl
, which will get theCollectionViewSource.GetDefaultView(Object)
for it, that is likely to be aListCollectionView
. So far... so good... However, as I just discovered today :-O :omg:, when usingAddRange()
,RemoveRange()
, i.e. creatingAdd/Remove
events with more that 1 object will trigger the following error in theListCollectionView
:System.NotSupportedException: Range actions are not supported.
Stack Trace:
ListCollectionView.ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
AbstractInvocation.Proceed()
Invocation.CallBase() line 147
ReturnBaseOrDefaultValue.Execute(Invocation invocation) line 88
IInterceptor.Intercept(Invocation invocation) line 34
Interceptor.Intercept(IInvocation underlying) line 113
AbstractInvocation.Proceed()
NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)Mmm... unfortunate... :(( I can think of 2 possible fixes and I am undecided as to which one to use?! 1. When a range
Add/Remove
event if fired, instead fire aReset
event. 2. When a rangeAdd/Remove
event if fired, instead fire multipleAdd/Remove
single item events. 3. or.. mmm... have a FireEventMode property, which would let the user decide whether to use event as is, split it, or fire Reset. Wo.. what say you?A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
There's an open issue from 2019 regarding this: Support Bulk Operations in ListCollectionView via ObservableCollection<T> · Issue #1887 · dotnet/wpf · GitHub[^] Personally, I'd be inclined to look at the number of items added / removed, and fire individual events for a "small" number and a reset event for a "large" number. Of course, the definitions of "small" and "large" are up to you. :)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer