Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8115 from Kaktusbot/fix-missing-avaloni…
Browse files Browse the repository at this point in the history
…alist-notifycountchanged

Fix missing NotifyCountChanged in AvaloniaList.AddRange
  • Loading branch information
maxkatz6 authored and danwalmsley committed Jun 1, 2022
1 parent 8251d79 commit 6cce833
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Avalonia.Base/Collections/AvaloniaList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ public virtual void InsertRange(int index, IEnumerable<T> items)
} while (en.MoveNext());

if (notificationItems is not null)
{
NotifyAdd(notificationItems, index);
}
else
{
NotifyCountChanged();
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Avalonia.Base.UnitTests/Collections/AvaloniaListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ public void Adding_Items_Should_Raise_CollectionChanged()
Assert.True(raised);
}

[Fact]
public void AddRange_IEnumerable_Should_Raise_Count_PropertyChanged()
{
var target = new AvaloniaList<int>(new[] { 1, 2, 3, 4, 5 });
var raised = false;

target.PropertyChanged += (s, e) => {
Assert.Equal(e.PropertyName, nameof(target.Count));
Assert.Equal(target.Count, 7);
raised = true;
};

target.AddRange(Enumerable.Range(6, 2));

Assert.True(raised);
}

[Fact]
public void AddRange_Items_Should_Raise_Correct_CollectionChanged()
{
Expand Down

0 comments on commit 6cce833

Please sign in to comment.