public void ShowContextMenu(Point position) { ContextMenu.IsOpen = true; ContextMenu.Placement = PlacementMode.AbsolutePoint; ContextMenu.HorizontalOffset = position.X; ContextMenu.VerticalOffset = position.Y; Win32Api.SetForegroundWindow(_msgSink.MsgWinHandle); }
public static extern bool GetCursorPos(ref Point lpPoint);
private void MsgSinkOnMouseEventReceived(MouseEvent mouseEvent) { switch (mouseEvent) { case MouseEvent.RightMouseDown: var position = new Point(); Win32Api.GetCursorPos(ref position); _notifyIcon.ShowContextMenu(position); break; case MouseEvent.LeftMouseDoubleClick: if (_isActivated) HideAndDeactivate(); else ShowAndActivate(); break; case MouseEvent.LeftMouseDown: break; case MouseEvent.LeftMouseUp: break; default: break; } }