From 1845b0a70f1d575d22006c4753660a8175a25ea6 Mon Sep 17 00:00:00 2001 From: punker76 Date: Mon, 7 Oct 2024 10:19:40 +0200 Subject: [PATCH] fix: #37 set focus to context menu to allow using esc when not focused --- src/NotifyIconWpf/TaskbarIcon.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/NotifyIconWpf/TaskbarIcon.cs b/src/NotifyIconWpf/TaskbarIcon.cs index 8d7cf4b..d10a3d9 100644 --- a/src/NotifyIconWpf/TaskbarIcon.cs +++ b/src/NotifyIconWpf/TaskbarIcon.cs @@ -1,4 +1,4 @@ -// hardcodet.net NotifyIcon for WPF +// hardcodet.net NotifyIcon for WPF // Copyright (c) 2009 - 2022 Philipp Sumi. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // Contact and Information: http://www.hardcodet.net @@ -783,6 +783,9 @@ private void ShowContextMenu(Point cursorPosition) // fallback, the context menu can't receive keyboard events - should not happen though WinApi.SetForegroundWindow(handle); + // set also the focus to the context menu, so that the keyboard works (using ESC if mouse is not over context menu). + ContextMenu.Focus(); + // bubble event RaiseTrayContextMenuOpenEvent(); }