From 651c4be0246202b7f28412cad089c72dd1f05c4c Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 2 Jun 2022 10:03:27 -0400 Subject: [PATCH] Merge pull request #8246 from AvaloniaUI/fixes/flyout-not-opening-more-than-once re-set popup.Parent if its no longer set. --- src/Avalonia.Controls/Flyouts/FlyoutBase.cs | 2 +- .../FlyoutTests.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs index bdabfbd6c8d..0c1eed75343 100644 --- a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs +++ b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs @@ -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); diff --git a/tests/Avalonia.Controls.UnitTests/FlyoutTests.cs b/tests/Avalonia.Controls.UnitTests/FlyoutTests.cs index 8b77074960d..776b4508c20 100644 --- a/tests/Avalonia.Controls.UnitTests/FlyoutTests.cs +++ b/tests/Avalonia.Controls.UnitTests/FlyoutTests.cs @@ -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(flyout.Popup); + Assert.NotNull(popup.Parent); + + flyout.Hide(); + + flyout.ShowAt(userControl); + Assert.NotNull(popup.Parent); + } + } [Fact] public void ContextFlyout_Can_Be_Set_In_Styles()