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:
Philipp Sumi
2013-11-17 23:10:18 +00:00
parent b10992dc25
commit 16ef216a4c

View File

@@ -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();