Description
This is a carry over from .NET Framework.
If INotifyCollectionChanged.CollectionChanged -> NotifyCollectionChangedEventArgs.NewItems has more than one item, most WPF controls will throw an exception.
The main reason for this original design is that ObservableCollection doesn't have an AddRange method and the controls assum that nothing else will support INotifyCollectionChanged.
Activity
dotMorten commentedon Dec 4, 2018
Yes! This has been extremely annoying. Being able to trigger one large change for a set of items without causing UI relayout over and over again would be a huge perf improvement. The interface completely supports this, but for some reason WPF never has. Currently our only choice is to trigger a reset event, which causes a complete relayout of all items.
benaadams commentedon Dec 4, 2018
The following apis have been approved for
Collection<T>
andObservableCollection<T>
in .NET Core; though not implemented yet https://github.com/dotnet/corefx/issues/10752:dotMorten commentedon Dec 4, 2018
This isn't about ObservableCollection, but about INotifyCollectionChanged interface. Any collection can implement that interface and have add-range, or be adding items in "chunks" (like incrementally loading datasources etc)
airbreather commentedon Dec 4, 2018
I was under the impression that it's "just"
System.Windows.Data.CollectionView
which would need to change, and that (in theory) something else could implementSystem.ComponentModel.ICollectionView
to get the desired benefits.Admittedly, however, I haven't tried it... am I mistaken?
Edit: that said,
System.ComponentModel.ICollectionView
itself extendsSystem.Collections.Specialized.INotifyCollectionChanged
, which makes me think thatSystem.Windows.Data.CollectionView
is likely to be just the most visible of, perhaps, many places that don't support batched changes...YZahringer commentedon Apr 18, 2021
Could be a 6.0.0 candidate? This currently blocks the range support in .net 6 ObservableCollection
DamirLisak commentedon Aug 16, 2023
In this context, I would like to point out the following problem:
dotnet/efcore#12675
EF core uses ObservableHashSet that implements INotifyCollectionChanged. However, the ObservableHashSet is an unsorted collection and is not able to specify an index in the OldStartingIndex property for a Remove action. This leads to an exception at this point in the EnumerableCollectionView.cs:
wpf/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs
Line 423 in 026f338
In this case, the entire CollectionView would have to be reloaded.
symbiogenesis commentedon Jan 26, 2024
This is one of the top-requested features in all of the world of .NET, going back many years. Offering this is crucial.
dotMorten commentedon Jul 5, 2024
Suggestion: We don't we log an issue for each control that have a problem with multi-item changes, and that way we can start chipping away at it and hopefully get to a point where we can add
AddRange
toObservableCollection<T>
? This issue could then be the epic for the individual tasks.symbiogenesis commentedon Jul 8, 2024
@anjali-wpf @singhashish-wpf
5 remaining items