Skip to content

Commit 01547d9

Browse files
Merge pull request dotnet#2097 from wpfcontrib/contextmenu_fixup
Context Menus are sometimes not shown in High-DPI applications
2 parents b57b7bb + 0437c64 commit 01547d9

File tree

1 file changed

+29
-7
lines changed
  • src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives

1 file changed

+29
-7
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs

+29-7
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ private void CreateWindow(bool asyncCall)
15101510
// cascading failure.
15111511
if (PopupInitialPlacementHelper.IsPerMonitorDpiScalingActive)
15121512
{
1513-
DestroyWindow();
1513+
DestroyWindowImpl();
15141514
_positionInfo = null;
15151515
makeNewWindow = true;
15161516
}
@@ -1601,18 +1601,40 @@ private void BuildWindow(Visual targetVisual)
16011601
_secHelper.BuildWindow(origin.x, origin.y, targetVisual, IsTransparent, PopupFilterMessage, OnWindowResize, OnDpiChanged);
16021602
}
16031603

1604-
private void DestroyWindow()
1604+
/// <summary>
1605+
/// Destroys the underlying window (HWND) if it is alive
1606+
/// </summary>
1607+
/// <returns>true if the window was destroyed, otherwise false</returns>
1608+
private bool DestroyWindowImpl()
16051609
{
16061610
if (_secHelper.IsWindowAlive())
16071611
{
16081612
_secHelper.DestroyWindow(PopupFilterMessage, OnWindowResize, OnDpiChanged);
1609-
ReleasePopupCapture();
1613+
return true;
1614+
}
16101615

1611-
// Raise closed event after popup has actually closed
1612-
OnClosed(EventArgs.Empty);
1616+
return false;
1617+
}
16131618

1614-
// When closing, clear the placement target registration
1615-
UpdatePlacementTargetRegistration(PlacementTarget, null);
1619+
/// <summary>
1620+
/// Destroys the window, and does additional book-keeping
1621+
/// like releasing the capture, raising Closed event, and
1622+
/// clearing placement-target registration
1623+
/// </summary>
1624+
private void DestroyWindow()
1625+
{
1626+
if (_secHelper.IsWindowAlive())
1627+
{
1628+
if (DestroyWindowImpl())
1629+
{
1630+
ReleasePopupCapture();
1631+
1632+
// Raise closed event after popup has actually closed
1633+
OnClosed(EventArgs.Empty);
1634+
1635+
// When closing, clear the placement target registration
1636+
UpdatePlacementTargetRegistration(PlacementTarget, null);
1637+
}
16161638
}
16171639
}
16181640

0 commit comments

Comments
 (0)