From 1a9ed2052aaeea6386a12523239d7d22aeb6dae3 Mon Sep 17 00:00:00 2001 From: John Boyer Date: Mon, 10 Oct 2022 18:04:54 +1100 Subject: [PATCH] Fixed DataGrid not properly removing multiple items on collection changed. --- .../Collections/DataGridCollectionView.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs b/src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs index 41d7883047..30517f4b00 100644 --- a/src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs +++ b/src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs @@ -3413,13 +3413,15 @@ namespace Avalonia.Collections return; } - object removedItem = args.OldItems?[0]; - // fire notifications for removes - if (args.Action == NotifyCollectionChangedAction.Remove || - args.Action == NotifyCollectionChangedAction.Replace) + if (args.OldItems != null && + (args.Action == NotifyCollectionChangedAction.Remove || + args.Action == NotifyCollectionChangedAction.Replace)) { - ProcessRemoveEvent(removedItem, args.Action == NotifyCollectionChangedAction.Replace); + foreach (var removedItem in args.OldItems) + { + ProcessRemoveEvent(removedItem, args.Action == NotifyCollectionChangedAction.Replace); + } } // fire notifications for adds