Browse Source

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

Addresses #8970, Fixes DataGrid not processing all new items on change.
pull/9198/head
Max Katz 4 years ago
committed by GitHub
parent
commit
c7d10ac09d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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(); RefreshOrDefer();
return; return;
} }
object addedItem = args.NewItems?[0];
object removedItem = args.OldItems?[0];
// fire notifications for removes // fire notifications for removes
if (args.Action == NotifyCollectionChangedAction.Remove || if (args.OldItems != null &&
args.Action == NotifyCollectionChangedAction.Replace) (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 // fire notifications for adds
if ((args.Action == NotifyCollectionChangedAction.Add || if (args.NewItems != null &&
args.Action == NotifyCollectionChangedAction.Replace) && (args.Action == NotifyCollectionChangedAction.Add ||
(Filter == null || PassesFilter(addedItem))) 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) if (args.Action != NotifyCollectionChangedAction.Replace)
{ {

Loading…
Cancel
Save