mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-16 11:08:30 -05:00
FIX Activating context menu itself rather than messagesink window, in order for the menu to receive keyboard input (NTFY-3).
git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@184 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
@@ -703,9 +703,22 @@ namespace Hardcodet.Wpf.TaskbarNotification
|
|||||||
|
|
||||||
ContextMenu.IsOpen = true;
|
ContextMenu.IsOpen = true;
|
||||||
|
|
||||||
//activate the message window to track deactivation - otherwise, the context menu
|
IntPtr handle = IntPtr.Zero;
|
||||||
//does not close if the user clicks somewhere else
|
|
||||||
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
|
//try to get a handle on the context itself
|
||||||
|
HwndSource source = (HwndSource)PresentationSource.FromVisual(ContextMenu);
|
||||||
|
if (source != null)
|
||||||
|
{
|
||||||
|
handle = source.Handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if we don't have a handle for the popup, fall back to the message sink
|
||||||
|
if (handle == IntPtr.Zero) handle = messageSink.MessageWindowHandle;
|
||||||
|
|
||||||
|
//activate the context menu or the message window to track deactivation - otherwise, the context menu
|
||||||
|
//does not close if the user clicks somewhere else. With the message window
|
||||||
|
//fallback, the context menu can't receive keyboard events - should not happen though
|
||||||
|
WinApi.SetForegroundWindow(handle);
|
||||||
|
|
||||||
//bubble event
|
//bubble event
|
||||||
RaiseTrayContextMenuOpenEvent();
|
RaiseTrayContextMenuOpenEvent();
|
||||||
|
|||||||
Reference in New Issue
Block a user