INotifyCollectionChanged
is implemented inconsistently for Move
and Replace
operations.
#17157
Labels
INotifyCollectionChanged
is implemented inconsistently for Move
and Replace
operations.
#17157
Describe the bug
Various
INotifyCollectionChanged.CollectionChanged
event handlers in Avalonia have an off-by-one error and / or fail to correctly respond to multi-item change events. For example, the following event handler does not respond to multi-itemMove
orReplace
operations correctly.Avalonia/src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs
Lines 95 to 99 in 981f47f
To correctly implement this type of behavior, we should follow the example of MAUI.
https://github.com/dotnet/maui/blob/cc683f0e99547c2ed4875296d7451332ef64ca73/src/Controls/src/Core/Internals/NotifyCollectionChangedEventArgsExtensions.cs#L47-L61
Furthermore, the event publishers are not consistent in their interpretations of
INotifyCollectionChanged
. For example, theAvaloniaList.Move
andAvaloniaList.MoveRange
methods produce different events for the same mutation (or, equivalently, the same events for different mutations). See the below unit test reflecting this incongruity.To Reproduce
To reproduce one of these behaviors, call
AvaloniaList.MoveRange
and verify that it successfully mutates the list, but fails to correctly update thePanelContainerGenerator
.Expected behavior
AvaloniaList.Move
andAvaloniaList.MoveRange
operations should throw exceptions before emitting events that will cause subsequent listeners to throw exceptions due to mismatched indices.Move(X, Y)
should have the same meaning asMoveRange(X, 1, Y)
.INotifyCollectionChanged
handlers throughout Avalonia should interpret indices in the same way.Avalonia version
11.2.0-beta2
OS
Windows
Additional context
No response
The text was updated successfully, but these errors were encountered: