I have been trying to add a context menu to a notify icon (system tray icon). This is for my own custom WPF wrapper around the native Shell_NotifyIcon function.
I have been using the following code to show a context menu:
contextMenu.Placement = PlacementMode.AbsolutePoint;
contextMenu.HorizontalOffset = args.X;
contextMenu.VerticalOffset = args.Y;
contextMenu.IsOpen = true;
The args.X
and args.Y
are the absolute screen coordinates of the mouse at the time the notify icon was clicked (I have verified that it contains the correct mouse position).
For some reason, the context menu shows up about 5-7 pixels up and to the left of the mouse position:
The context menus of the other icons on the system tray display exactly where the mouse is.
I searched all the available properties of the ContextMenu and nothing seemed like it would fix it. Am I missing something? I could always manually adjust by 7 or so pixels but if there is a better way I'd rather do whatever that way may be.