/// <summary> /// Displays the <see cref="TrayPopup"/> control if /// it was set. /// </summary> private void ShowTrayPopup(TweetOBoxMain.Notifications.Interop.Point cursorPosition) { if (IsDisposed) return; //raise preview event no matter whether popup is currently set //or not (enables client to set it on demand) var args = RaisePreviewTrayPopupOpenEvent(); if (args.Handled) return; if (TrayPopup != null) { //use absolute position, but place the popup centered above the icon TrayPopupResolved.Placement = PlacementMode.AbsolutePoint; TrayPopupResolved.HorizontalOffset = cursorPosition.X; TrayPopupResolved.VerticalOffset = cursorPosition.Y; //open popup TrayPopupResolved.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); //raise attached event - item should never be null unless developers //changed the CustomPopup directly... if (TrayPopup != null) RaisePopupOpenedEvent(TrayPopup); //bubble routed event RaiseTrayPopupOpenEvent(); } }
/// <summary> /// Displays the <see cref="ContextMenu"/> if /// it was set. /// </summary> private void ShowContextMenu(TweetOBoxMain.Notifications.Interop.Point cursorPosition) { if (IsDisposed) return; //raise preview event no matter whether context menu is currently set //or not (enables client to set it on demand) var args = RaisePreviewTrayContextMenuOpenEvent(); if (args.Handled) return; if (ContextMenu != null) { //use absolute position ContextMenu.Placement = PlacementMode.AbsolutePoint; ContextMenu.HorizontalOffset = cursorPosition.X; ContextMenu.VerticalOffset = cursorPosition.Y; 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); //bubble event RaiseTrayContextMenuOpenEvent(); } }