diff --git a/src/Avalonia.Base/Collections/AvaloniaDictionary.cs b/src/Avalonia.Base/Collections/AvaloniaDictionary.cs index 0e027712e0d0..2fe68e824dbf 100644 --- a/src/Avalonia.Base/Collections/AvaloniaDictionary.cs +++ b/src/Avalonia.Base/Collections/AvaloniaDictionary.cs @@ -146,6 +146,7 @@ public bool Remove(TKey key) { if (_inner.TryGetValue(key, out var value)) { + _inner.Remove(key); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]")); diff --git a/tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs b/tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs index df3ca4e4dc7c..739c3fed7985 100644 --- a/tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs +++ b/tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Collections.Specialized; using Avalonia.Collections; @@ -104,6 +105,16 @@ public void Removing_Item_Should_Raise_CollectionChanged() Assert.Equal(new KeyValuePair("foo", "bar"), tracker.Args.OldItems[0]); } + [Fact] + public void Remove_Method_Should_Remove_Item_From_Collection() + { + var target = new AvaloniaDictionary() { { "foo", "bar" } }; + Assert.Equal(target.Count, 1); + + target.Remove("foo"); + Assert.Equal(target.Count, 0); + } + [Fact] public void Removing_Item_Should_Raise_PropertyChanged() {