Browse Source

Merge pull request #8115 from Kaktusbot/fix-missing-avalonialist-notifycountchanged

Fix missing NotifyCountChanged in AvaloniaList.AddRange
Max Katz 3 years ago
parent
commit
28f8bf8fbc

+ 6 - 0
src/Avalonia.Base/Collections/AvaloniaList.cs

@@ -394,7 +394,13 @@ namespace Avalonia.Collections
                         } while (en.MoveNext());
 
                         if (notificationItems is not null)
+                        {
                             NotifyAdd(notificationItems, index);
+                        }
+                        else
+                        {
+                            NotifyCountChanged();
+                        }
                     }
                 }
             }

+ 17 - 0
tests/Avalonia.Base.UnitTests/Collections/AvaloniaListTests.cs

@@ -146,6 +146,23 @@ namespace Avalonia.Base.UnitTests.Collections
             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()
         {