mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-01-14 01:25:45 -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;
|
||||
|
||||
//activate the message window to track deactivation - otherwise, the context menu
|
||||
//does not close if the user clicks somewhere else
|
||||
WinApi.SetForegroundWindow(messageSink.MessageWindowHandle);
|
||||
IntPtr handle = IntPtr.Zero;
|
||||
|
||||
//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
|
||||
RaiseTrayContextMenuOpenEvent();
|
||||
|
||||
Reference in New Issue
Block a user