Skip to content

Commit 28f8f45

Browse files
authored
Preventing focus steal if parent window/application is not active (#1169)
* Preventing focus steal if parent window/application is not active * Improving condition to cause focus when there is no window present * Improving comment * Fixing typo * Fixing code
1 parent 166bb4d commit 28f8f45

File tree

1 file changed

+4
-1
lines changed
  • src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls

1 file changed

+4
-1
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,10 @@ private void FocusOrSelect()
25152515
// but if we fail to focus we should still select.
25162516
// (This is to help enable focusless menus).
25172517
// Check IsKeyboardFocusWithin to allow rich content within the menuitem.
2518-
if (!IsKeyboardFocusWithin)
2518+
if (!IsKeyboardFocusWithin
2519+
// But only acquire focus if the window we are inside of is currently active or there is no window.
2520+
// Otherwise we would potentially steal focus from other applications.
2521+
&& (Window.GetWindow(this)?.IsActive ?? true))
25192522
{
25202523
Focus();
25212524
}

0 commit comments

Comments
 (0)