Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8246 from AvaloniaUI/fixes/flyout-not-o…
Browse files Browse the repository at this point in the history
…pening-more-than-once

re-set popup.Parent if its no longer set.
  • Loading branch information
maxkatz6 authored and danwalmsley committed Jun 2, 2022
1 parent 30e8b17 commit 651c4be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Flyouts/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected virtual bool ShowAtCore(Control placementTarget, bool showAtPointer =
((ISetLogicalParent)Popup).SetParent(null);
}

if (Popup.PlacementTarget != placementTarget)
if (Popup.Parent == null || Popup.PlacementTarget != placementTarget)
{
Popup.PlacementTarget = Target = placementTarget;
((ISetLogicalParent)Popup).SetParent(placementTarget);
Expand Down
22 changes: 22 additions & 0 deletions tests/Avalonia.Controls.UnitTests/FlyoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,28 @@ public void Should_Reset_Popup_Parent_On_Target_Detached()
Assert.Null(popup.Parent);
}
}

[Fact]
public void Should_Reset_Popup_Parent_On_Target_Attach_Following_Detach()
{
using (CreateServicesWithFocus())
{
var userControl = new UserControl();
var window = PreparedWindow(userControl);
window.Show();

var flyout = new TestFlyout();
flyout.ShowAt(userControl);

var popup = Assert.IsType<Popup>(flyout.Popup);
Assert.NotNull(popup.Parent);

flyout.Hide();

flyout.ShowAt(userControl);
Assert.NotNull(popup.Parent);
}
}

[Fact]
public void ContextFlyout_Can_Be_Set_In_Styles()
Expand Down

0 comments on commit 651c4be

Please sign in to comment.