Skip to content

Commit 651c4be

Browse files
maxkatz6danwalmsley
authored andcommitted
Merge pull request AvaloniaUI#8246 from AvaloniaUI/fixes/flyout-not-opening-more-than-once
re-set popup.Parent if its no longer set.
1 parent 30e8b17 commit 651c4be

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Avalonia.Controls/Flyouts/FlyoutBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ protected virtual bool ShowAtCore(Control placementTarget, bool showAtPointer =
221221
((ISetLogicalParent)Popup).SetParent(null);
222222
}
223223

224-
if (Popup.PlacementTarget != placementTarget)
224+
if (Popup.Parent == null || Popup.PlacementTarget != placementTarget)
225225
{
226226
Popup.PlacementTarget = Target = placementTarget;
227227
((ISetLogicalParent)Popup).SetParent(placementTarget);

tests/Avalonia.Controls.UnitTests/FlyoutTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,28 @@ public void Should_Reset_Popup_Parent_On_Target_Detached()
451451
Assert.Null(popup.Parent);
452452
}
453453
}
454+
455+
[Fact]
456+
public void Should_Reset_Popup_Parent_On_Target_Attach_Following_Detach()
457+
{
458+
using (CreateServicesWithFocus())
459+
{
460+
var userControl = new UserControl();
461+
var window = PreparedWindow(userControl);
462+
window.Show();
463+
464+
var flyout = new TestFlyout();
465+
flyout.ShowAt(userControl);
466+
467+
var popup = Assert.IsType<Popup>(flyout.Popup);
468+
Assert.NotNull(popup.Parent);
469+
470+
flyout.Hide();
471+
472+
flyout.ShowAt(userControl);
473+
Assert.NotNull(popup.Parent);
474+
}
475+
}
454476

455477
[Fact]
456478
public void ContextFlyout_Can_Be_Set_In_Styles()

0 commit comments

Comments
 (0)