Skip to content

Commit cd13998

Browse files
fix(menuflyout): Ensure MenuFlyout nested submenus stay on screen
Fix bug where nested submenus could be shown offscreen on the 2nd and later times they appeared.
1 parent 779e773 commit cd13998

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Uno.UI/UI/Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ internal class CascadingMenuHelper
5353
// This fallback is used if we fail to retrieve a value from the MenuShowDelay RegKey
5454
const int DefaultMenuShowDelay = 400; // in milliseconds
5555

56+
// Uno-specific workaround (see comment below)
57+
private Point? _lastTargetPoint;
58+
5659
public CascadingMenuHelper()
5760
{
5861
m_isPointerOver = false;
@@ -567,6 +570,13 @@ internal void OpenSubMenu()
567570
}
568571

569572
ownerAsSubMenuOwner.OpenSubMenu(targetPoint);
573+
if (_lastTargetPoint is { } lastTargetPoint)
574+
{
575+
// Uno-specific workaround: reapply the location calculated in OnPresenterSizeChanged(), since that one properly
576+
// adjusts to keep submenu within screen bounds. (WinUI seemingly relies upon presenter.SizeChanged being raised
577+
// every time submenu opens? On Uno it isn't.)
578+
ownerAsSubMenuOwner.PositionSubMenu(lastTargetPoint);
579+
}
570580
ownerAsSubMenuOwner.RaiseAutomationPeerExpandCollapse(true /* isOpen */);
571581
ElementSoundPlayer.RequestInteractionSoundForElement(ElementSoundKind.Invoke, ownerAsControl);
572582
}
@@ -932,6 +942,7 @@ internal void OnPresenterSizeChanged(
932942
}
933943
}
934944

945+
_lastTargetPoint = targetPoint;
935946
ownerAsSubMenuOwner.PositionSubMenu(targetPoint);
936947
}
937948
}

0 commit comments

Comments
 (0)