Browse Source

Only call property notify on effective value change.

pull/3854/head
Steven Kirk 6 years ago
parent
commit
c872cc005d
  1. 10
      src/Avalonia.Base/AvaloniaObject.cs
  2. 20
      tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs

10
src/Avalonia.Base/AvaloniaObject.cs

@ -716,7 +716,10 @@ namespace Avalonia
{ {
VerifyAccess(); VerifyAccess();
change.Property.Notifying?.Invoke(this, true); if (change.IsEffectiveValueChange)
{
change.Property.Notifying?.Invoke(this, true);
}
try try
{ {
@ -747,7 +750,10 @@ namespace Avalonia
} }
finally finally
{ {
change.Property.Notifying?.Invoke(this, false); if (change.IsEffectiveValueChange)
{
change.Property.Notifying?.Invoke(this, false);
}
} }
} }

20
tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs

@ -102,6 +102,17 @@ namespace Avalonia.Base.UnitTests
Assert.Equal(new[] { "animated" }, result); Assert.Equal(new[] { "animated" }, result);
} }
[Fact]
public void Notify_Fired_Only_On_Effective_Value_Change()
{
var target = new Class1();
target.SetValue(Class1.FooProperty, "animated", BindingPriority.Animation);
target.SetValue(Class1.FooProperty, "local");
Assert.Equal(2, target.NotifyCount);
}
[Fact] [Fact]
public void Property_Equals_Should_Handle_Null() public void Property_Equals_Should_Handle_Null()
{ {
@ -180,7 +191,14 @@ namespace Avalonia.Base.UnitTests
private class Class1 : AvaloniaObject private class Class1 : AvaloniaObject
{ {
public static readonly StyledProperty<string> FooProperty = public static readonly StyledProperty<string> FooProperty =
AvaloniaProperty.Register<Class1, string>("Foo", "default"); AvaloniaProperty.Register<Class1, string>("Foo", "default", notifying: FooNotifying);
public int NotifyCount { get; private set; }
private static void FooNotifying(IAvaloniaObject o, bool n)
{
++((Class1)o).NotifyCount;
}
} }
private class Class2 : Class1 private class Class2 : Class1

Loading…
Cancel
Save