Skip to content

Commit

Permalink
Set logical parent
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Oct 24, 2024
1 parent 4595ed2 commit 46b4ced
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Avalonia.Xaml.Interactivity/StyledElementBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Globalization;
using Avalonia.Controls;
using Avalonia.LogicalTree;
using Avalonia.Reactive;

namespace Avalonia.Xaml.Interactivity;
Expand Down Expand Up @@ -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();
}

Expand All @@ -73,6 +80,12 @@ public void Detach()
{
OnDetaching();
_dataContextDisposable?.Dispose();

if (AssociatedObject is StyledElement)
{
((ISetLogicalParent)this).SetParent(null);
}

AssociatedObject = null;
}

Expand Down

0 comments on commit 46b4ced

Please sign in to comment.