Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-set popup.Parent if its no longer set. #8246

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Flyouts/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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