Browse Source
Merge branch 'master' into cleanup-csproj
pull/1549/head
Steven Kirk
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
36 additions and
4 deletions
-
src/Avalonia.Base/AvaloniaObject.cs
-
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Attached.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>
|
|
|
|
|
|
|
|
@ -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 |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|