Wpf: Support Bulk Operations in ListCollectionView via ObservableCollection<T>

Created on 13 Sep 2019  路  2Comments  路  Source: dotnet/wpf

To support corefx 10752, surfaced by corefx issue 38085.

In .NET Core 3 Preview 7, the CoreFX team introduced support for ranges via Collection<T> and ObservableCollection<T>. WPF is not able to handle how the new implementation of AddRange on Collection<T> as the add is done as a bulk insert at the end which changes the behavior of 'ListCollectionView` which does not support bulk operations and throws an https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs#L2521.

The net effect here is that a common helper method that is used in many WPF apps (AddRange to an ObservableCollection<T> no longer binds and the replacement method's behavior has a negative and observable side effect.

Adding issue for .NET 5 consideration

issue-type-enhancement

Most helpful comment

/cc @karelz, @robertmclaws

All 2 comments

This is actually a longstanding bug in WPF, throwing from a INotifyCollectionChanged event handler is not allowed, you are consuming the events and are not in control of the origin. Correct implementation would be to fall back to the Reset case when you encounter a situation you cannot handle.

The usual workaround is to put a proxy between WPF and the event source, to translate events WPF doesn't understand into reset events.

/cc @karelz, @robertmclaws

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liquidboy picture liquidboy  路  3Comments

JeroenOortwijn picture JeroenOortwijn  路  3Comments

TobiasSekan picture TobiasSekan  路  3Comments

imanushin picture imanushin  路  3Comments

h82258652 picture h82258652  路  3Comments