Browse Source

Merge branch 'master' into cleanup-csproj

pull/1549/head
Steven Kirk 8 years ago
committed by GitHub
parent
commit
ef3afccaa8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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()
{
VerifyAccess();
foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(this))
void Notify(AvaloniaProperty property)
{
object value = property.IsDirect ?
((IDirectPropertyAccessor)property).GetValue(this) :
@ -86,6 +87,16 @@ namespace Avalonia
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>

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

@ -24,10 +24,27 @@ namespace Avalonia.Base.UnitTests
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 =
AvaloniaProperty.RegisterAttached<Class1, Class2, string>(
AvaloniaProperty.RegisterAttached<Class1, Base, string>(
"Foo",
"foodefault",
validate: ValidateFoo);
@ -43,10 +60,14 @@ namespace Avalonia.Base.UnitTests
}
}
private class Class2 : AvaloniaObject
private class Class2 : Base
{
public static readonly AttachedProperty<string> FooProperty =
Class1.FooProperty.AddOwner<Class2>();
}
private class Class3 : Base
{
}
}
}

Loading…
Cancel
Save