Browse Source

Merge pull request #9135 from ghasttear1/8970-datagrid-add-multiple-fix

Addresses #8970, Fixes DataGrid not processing all new items on change.
stable/0.10.x-outsys
Max Katz 3 years ago
committed by Steven Kirk
parent
commit
d59d66e07d
  1. 29
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

29
src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

@ -3412,23 +3412,30 @@ namespace Avalonia.Collections
RefreshOrDefer();
return;
}
object addedItem = args.NewItems?[0];
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
if ((args.Action == NotifyCollectionChangedAction.Add ||
args.Action == NotifyCollectionChangedAction.Replace) &&
(Filter == null || PassesFilter(addedItem)))
if (args.NewItems != null &&
(args.Action == NotifyCollectionChangedAction.Add ||
args.Action == NotifyCollectionChangedAction.Replace))
{
ProcessAddEvent(addedItem, args.NewStartingIndex);
for (var i = 0; i < args.NewItems.Count; i++)
{
if (Filter == null || PassesFilter(args.NewItems[i]))
{
ProcessAddEvent(args.NewItems[i], args.NewStartingIndex + i);
}
}
}
if (args.Action != NotifyCollectionChangedAction.Replace)
{

Loading…
Cancel
Save