Browse Source

Merge branch 'master' into fixes/has-system-decoration-false

pull/1574/head
Dan Walmsley 8 years ago
parent
commit
1c193eb985
  1. 13
      src/Avalonia.Base/AvaloniaObject.cs
  2. 27
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Attached.cs

13
src/Avalonia.Base/AvaloniaObject.cs

@ -71,7 +71,8 @@ namespace Avalonia
public AvaloniaObject() public AvaloniaObject()
{ {
VerifyAccess(); VerifyAccess();
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(this))
void Notify(AvaloniaProperty property)
{ {
object value = property.IsDirect ? object value = property.IsDirect ?
((IDirectPropertyAccessor)property).GetValue(this) : ((IDirectPropertyAccessor)property).GetValue(this) :
@ -86,6 +87,16 @@ namespace Avalonia
property.NotifyInitialized(e); property.NotifyInitialized(e);
} }
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(this))
{
Notify(property);
}
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegisteredAttached(this.GetType()))
{
Notify(property);
}
} }
/// <summary> /// <summary>

27
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Attached.cs

@ -24,10 +24,27 @@ namespace Avalonia.Base.UnitTests
Assert.Throws<IndexOutOfRangeException>(() => target.SetValue(Class2.FooProperty, "throw")); Assert.Throws<IndexOutOfRangeException>(() => target.SetValue(Class2.FooProperty, "throw"));
} }
private class Class1 : AvaloniaObject [Fact]
public void AvaloniaProperty_Initialized_Is_Called_For_Attached_Property()
{
bool raised = false;
using (Class1.FooProperty.Initialized.Subscribe(x => raised = true))
{
new Class3();
}
Assert.True(raised);
}
private class Base : AvaloniaObject
{
}
private class Class1 : Base
{ {
public static readonly AttachedProperty<string> FooProperty = public static readonly AttachedProperty<string> FooProperty =
AvaloniaProperty.RegisterAttached<Class1, Class2, string>( AvaloniaProperty.RegisterAttached<Class1, Base, string>(
"Foo", "Foo",
"foodefault", "foodefault",
validate: ValidateFoo); validate: ValidateFoo);
@ -43,10 +60,14 @@ namespace Avalonia.Base.UnitTests
} }
} }
private class Class2 : AvaloniaObject private class Class2 : Base
{ {
public static readonly AttachedProperty<string> FooProperty = public static readonly AttachedProperty<string> FooProperty =
Class1.FooProperty.AddOwner<Class2>(); Class1.FooProperty.AddOwner<Class2>();
} }
private class Class3 : Base
{
}
} }
} }

Loading…
Cancel
Save