From 18d2238b91b00302f676297788ff5848c5c8252a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 30 Mar 2020 20:21:54 +0200 Subject: [PATCH] Remove sanity check from SetParent. In the case of #3708, the sanity check fails because the parent call to `SetParent` hasn't yet completed - it's the setting of `InheritanceParent` on the parent that causes the child to get attached. --- src/Avalonia.Styling/StyledElement.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Styling/StyledElement.cs b/src/Avalonia.Styling/StyledElement.cs index 241ca1d0ec..1a4bc5b3a3 100644 --- a/src/Avalonia.Styling/StyledElement.cs +++ b/src/Avalonia.Styling/StyledElement.cs @@ -453,18 +453,14 @@ namespace Avalonia NotifyResourcesChanged(new ResourcesChangedEventArgs()); - if (Parent is ILogicalRoot || Parent?.IsAttachedToLogicalTree == true || this is ILogicalRoot) - { - var newRoot = FindLogicalRoot(this); - - if (newRoot == null) - { - throw new AvaloniaInternalException("Parent is attached to logical tree but cannot find root."); - } + var newRoot = FindLogicalRoot(this); + if (newRoot is object) + { var e = new LogicalTreeAttachmentEventArgs(newRoot, this, parent); OnAttachedToLogicalTreeCore(e); } + #nullable disable RaisePropertyChanged( ParentProperty, @@ -618,7 +614,7 @@ namespace Avalonia } } - private static ILogicalRoot? FindLogicalRoot(IStyleHost e) + private static ILogicalRoot? FindLogicalRoot(IStyleHost? e) { while (e != null) {