예제 #1
0
        // Should the command menu be shown based on the event type?
        protected bool ShouldShowCommandMenu(Wpf.EventType eventType)
        {
            // Check for single event types
            if (MenuActivation == eventType)
            {
                return(true);
            }

            // Check for compound types
            switch (MenuActivation)
            {
            case Wpf.EventType.Any:
                return(true);

            case Wpf.EventType.DoubleClick:
                if (eventType == Wpf.EventType.LeftButtonDoubleClick ||
                    eventType == Wpf.EventType.MiddleButtonDoubleClick ||
                    eventType == Wpf.EventType.RightButtonDoubleClick)
                {
                    return(true);
                }
                break;

            case Wpf.EventType.SingleClick:
                if (eventType == Wpf.EventType.LeftButtonSingleClick ||
                    eventType == Wpf.EventType.MiddleButtonSingleClick ||
                    eventType == Wpf.EventType.RightButtonSingleClick)
                {
                    return(true);
                }
                break;
            }

            return(false);
        }
예제 #2
0
        // Called when a window even occurs in the notification area icon
        public void OnNotificationIconEvent(object sender, NotifyIconEventArgs e)
        {
            // Convert from the Win32 event type to the wpf event type
            if (e != null)
            {
                Wpf.EventType eventType = (Wpf.EventType)e.Type;

                // Forward the event to any commands
                ForwardEventToCommand(eventType);

                // Handle the content menu
                HandleCommandMenu(eventType, e.CursorX, e.CursorY);
            }
        }
예제 #3
0
 // Forward events to any registed commands
 protected void ForwardEventToCommand(Wpf.EventType eventType)
 {
     switch (eventType)
     {
     case Wpf.EventType.LeftButtonDoubleClick:
     case Wpf.EventType.MiddleButtonDoubleClick:
     case Wpf.EventType.RightButtonDoubleClick:
         // Handle double click
         if (DoubleClickCommand?.CanExecute(DoubleClickCommandParameter) == true)
         {
             DoubleClickCommand?.Execute(DoubleClickCommandParameter);
         }
         break;
     }
 }
예제 #4
0
        // Handle the display of the command menu, based on the event type
        protected void HandleCommandMenu(Wpf.EventType eventType, int cursorX, int cursorY)
        {
            if (ContextMenu != null)
            {
                // Should we
                if (ShouldShowCommandMenu(eventType))
                {
                    // Set the position of the menu
                    ContextMenu.Placement        = PlacementMode.AbsolutePoint;
                    ContextMenu.HorizontalOffset = cursorX;
                    ContextMenu.VerticalOffset   = cursorY;
                    ContextMenu.IsOpen           = true;

                    // Show the window
                    HwndSource hwndSource = PresentationSource.FromVisual(ContextMenu) as HwndSource;
                    if (hwndSource != null)
                    {
                        NotificationAreaIcon.SetForegroundWindow(hwndSource.Handle);
                    }
                }
            }
        }