Browse Source

Merge pull request #7430 from AvaloniaUI/avaloniadictionary-remove-fix

Fix AvaloniaDictionary Remove method
release/0.10.12
Benedikt Stebner 5 years ago
committed by Dan Walmsley
parent
commit
4652264bbc
  1. 1
      src/Avalonia.Base/Collections/AvaloniaDictionary.cs
  2. 11
      tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs

1
src/Avalonia.Base/Collections/AvaloniaDictionary.cs

@ -146,6 +146,7 @@ namespace Avalonia.Collections
{ {
if (_inner.TryGetValue(key, out var value)) if (_inner.TryGetValue(key, out var value))
{ {
_inner.Remove(key);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]"));

11
tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using Avalonia.Collections; using Avalonia.Collections;
@ -104,6 +105,16 @@ namespace Avalonia.Base.UnitTests.Collections
Assert.Equal(new KeyValuePair<string, string>("foo", "bar"), tracker.Args.OldItems[0]); Assert.Equal(new KeyValuePair<string, string>("foo", "bar"), tracker.Args.OldItems[0]);
} }
[Fact]
public void Remove_Method_Should_Remove_Item_From_Collection()
{
var target = new AvaloniaDictionary<string, string>() { { "foo", "bar" } };
Assert.Equal(target.Count, 1);
target.Remove("foo");
Assert.Equal(target.Count, 0);
}
[Fact] [Fact]
public void Removing_Item_Should_Raise_PropertyChanged() public void Removing_Item_Should_Raise_PropertyChanged()
{ {

Loading…
Cancel
Save