From 46b4ced1f8a9447b295df053bb6433f012c8b991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Thu, 24 Oct 2024 19:57:37 +0200 Subject: [PATCH] Set logical parent --- .../StyledElementBehavior.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Avalonia.Xaml.Interactivity/StyledElementBehavior.cs b/src/Avalonia.Xaml.Interactivity/StyledElementBehavior.cs index 4f633245..b3fd0cbb 100644 --- a/src/Avalonia.Xaml.Interactivity/StyledElementBehavior.cs +++ b/src/Avalonia.Xaml.Interactivity/StyledElementBehavior.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Globalization; using Avalonia.Controls; +using Avalonia.LogicalTree; using Avalonia.Reactive; namespace Avalonia.Xaml.Interactivity; @@ -63,6 +64,12 @@ public void Attach(AvaloniaObject? associatedObject) _dataContextDisposable = SynchronizeDataContext(associatedObject); + if (associatedObject is StyledElement styledElement) + { + ((ISetLogicalParent)this).SetParent(null); + ((ISetLogicalParent)this).SetParent(styledElement); + } + OnAttached(); } @@ -73,6 +80,12 @@ public void Detach() { OnDetaching(); _dataContextDisposable?.Dispose(); + + if (AssociatedObject is StyledElement) + { + ((ISetLogicalParent)this).SetParent(null); + } + AssociatedObject = null; }