From cd139987d0b14a53c6f842fb837404c8ccbc5878 Mon Sep 17 00:00:00 2001 From: David Oliver Date: Thu, 23 Sep 2021 09:23:14 -0400 Subject: [PATCH] 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. --- .../Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs b/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs index 1a062025b505..1d8f467926cf 100644 --- a/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs +++ b/src/Uno.UI/UI/Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs @@ -53,6 +53,9 @@ internal class CascadingMenuHelper // This fallback is used if we fail to retrieve a value from the MenuShowDelay RegKey const int DefaultMenuShowDelay = 400; // in milliseconds + // Uno-specific workaround (see comment below) + private Point? _lastTargetPoint; + public CascadingMenuHelper() { m_isPointerOver = false; @@ -567,6 +570,13 @@ internal void OpenSubMenu() } ownerAsSubMenuOwner.OpenSubMenu(targetPoint); + if (_lastTargetPoint is { } lastTargetPoint) + { + // Uno-specific workaround: reapply the location calculated in OnPresenterSizeChanged(), since that one properly + // adjusts to keep submenu within screen bounds. (WinUI seemingly relies upon presenter.SizeChanged being raised + // every time submenu opens? On Uno it isn't.) + ownerAsSubMenuOwner.PositionSubMenu(lastTargetPoint); + } ownerAsSubMenuOwner.RaiseAutomationPeerExpandCollapse(true /* isOpen */); ElementSoundPlayer.RequestInteractionSoundForElement(ElementSoundKind.Invoke, ownerAsControl); } @@ -932,6 +942,7 @@ public void OnVisibilityChanged() } } + _lastTargetPoint = targetPoint; ownerAsSubMenuOwner.PositionSubMenu(targetPoint); } }