diff --git a/src/Markup/Avalonia.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs b/src/Markup/Avalonia.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs index a62132be86..138f09b373 100644 --- a/src/Markup/Avalonia.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs +++ b/src/Markup/Avalonia.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs @@ -54,6 +54,7 @@ namespace Avalonia.Markup.Data.Plugins { private readonly WeakReference _reference; private readonly PropertyInfo _property; + private bool _eventRaised; public Accessor(WeakReference reference, PropertyInfo property) { @@ -79,7 +80,14 @@ namespace Avalonia.Markup.Data.Plugins { if (_property.CanWrite) { + _eventRaised = false; _property.SetValue(_reference.Target, value); + + if (!_eventRaised) + { + SendCurrentValue(); + } + return true; } @@ -90,6 +98,7 @@ namespace Avalonia.Markup.Data.Plugins { if (e.PropertyName == _property.Name || string.IsNullOrEmpty(e.PropertyName)) { + _eventRaised = true; SendCurrentValue(); } } @@ -134,16 +143,6 @@ namespace Avalonia.Markup.Data.Plugins nameof(inpc.PropertyChanged), this); } - else - { - Logger.Information( - LogArea.Binding, - this, - "Bound to property {Property} on {Source} which does not implement INotifyPropertyChanged", - _property.Name, - _reference.Target, - _reference.Target.GetType()); - } } } } diff --git a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Property.cs b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Property.cs index 887879b164..b65dd091e0 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Property.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Property.cs @@ -437,6 +437,32 @@ namespace Avalonia.Markup.UnitTests.Data } } + [Fact] + public void SetValue_Should_Notify_New_Value_With_Inpc() + { + var data = new Class1(); + var target = new ExpressionObserver(data, "Foo"); + var result = new List(); + + target.Subscribe(x => result.Add(x)); + target.SetValue("bar"); + + Assert.Equal(new[] { null, "bar" }, result); + } + + [Fact] + public void SetValue_Should_Notify_New_Value_Without_Inpc() + { + var data = new Class1(); + var target = new ExpressionObserver(data, "Bar"); + var result = new List(); + + target.Subscribe(x => result.Add(x)); + target.SetValue("bar"); + + Assert.Equal(new[] { null, "bar" }, result); + } + [Fact] public void SetValue_Should_Return_False_For_Missing_Object() {