Browse Source

Make sure new value is returned.

When a property value is set, if a new value isn't notified via INPC,
then send the new value after the set succeeds.
pull/691/head
Steven Kirk 10 years ago
parent
commit
5a9be7d94a
  1. 19
      src/Markup/Avalonia.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs
  2. 26
      tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Property.cs

19
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());
}
}
}
}

26
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<object>();
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<object>();
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()
{

Loading…
Cancel
Save