Example #1
0
 private void PostProcessInput(object sender, ProcessInputEventArgs e)
 {
     if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
     {
         if (!e.StagingItem.Input.Handled)
         {
             InputReportEventArgs inputReportEventArgs = e.StagingItem.Input as InputReportEventArgs;
             if (inputReportEventArgs != null)
             {
                 RawAppCommandInputReport rawAppCommandInputReport = inputReportEventArgs.Report as RawAppCommandInputReport;
                 if (rawAppCommandInputReport != null)
                 {
                     IInputElement commandTarget = e.StagingItem.Input.OriginalSource as IInputElement;
                     if (commandTarget != null)
                     {
                         RoutedCommand command = GetRoutedCommand(rawAppCommandInputReport.AppCommand);
                         if (command != null)
                         {
                             // Send the app command to the tree to be handled by UIElements and ContentElements
                             // that will forward the event to CommandManager.
                             CommandDeviceEventArgs args = new CommandDeviceEventArgs(this, rawAppCommandInputReport.Timestamp, command);
                             args.RoutedEvent = CommandDeviceEvent;
                             args.Source      = commandTarget;
                             e.PushInput(args, e.StagingItem);
                         }
                     }
                 }
             }
         }
     }
     else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent ||
              e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.GotKeyboardFocusEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.LostKeyboardFocusEvent)
     {
         CommandManager.InvalidateRequerySuggested();
     }
 }
Example #2
0
        internal static void OnCommandDevice(object sender, CommandDeviceEventArgs e)
        {
            if ((sender != null) && (e != null) && (e.Command != null))
            {
                CanExecuteRoutedEventArgs canExecuteArgs = new CanExecuteRoutedEventArgs(e.Command, null /* parameter */);
                canExecuteArgs.RoutedEvent = CommandManager.CanExecuteEvent;
                canExecuteArgs.Source      = sender;
                OnCanExecute(sender, canExecuteArgs);

                if (canExecuteArgs.CanExecute)
                {
                    ExecutedRoutedEventArgs executedArgs = new ExecutedRoutedEventArgs(e.Command, null /* parameter */);
                    executedArgs.RoutedEvent = CommandManager.ExecutedEvent;
                    executedArgs.Source      = sender;
                    OnExecuted(sender, executedArgs);

                    if (executedArgs.Handled)
                    {
                        e.Handled = true;
                    }
                }
            }
        }
        private static void OnCommandDeviceThunk(object sender, CommandDeviceEventArgs e)
        {
            Invariant.Assert(!e.Handled, "Unexpected: Event has already been handled.");

            // Command Manager will determine if preview or regular event.
            CommandManager.OnCommandDevice(sender, e);
        }
Example #4
0
        internal static void OnCommandDevice(object sender, CommandDeviceEventArgs e)
        {
            if ((sender != null) && (e != null) && (e.Command != null))
            {
                CanExecuteRoutedEventArgs canExecuteArgs = new CanExecuteRoutedEventArgs(e.Command, null /* parameter */);
                canExecuteArgs.RoutedEvent = CommandManager.CanExecuteEvent;
                canExecuteArgs.Source = sender;
                OnCanExecute(sender, canExecuteArgs);

                if (canExecuteArgs.CanExecute)
                {
                    ExecutedRoutedEventArgs executedArgs = new ExecutedRoutedEventArgs(e.Command, null /* parameter */);
                    executedArgs.RoutedEvent = CommandManager.ExecutedEvent;
                    executedArgs.Source = sender;
                    OnExecuted(sender, executedArgs);

                    if (executedArgs.Handled)
                    {
                        e.Handled = true;
                    }
                }
            }
        }
Example #5
0
 private void PostProcessInput( object sender, ProcessInputEventArgs e )
 {
     if (e.StagingItem.Input.RoutedEvent == InputManager.InputReportEvent)
     {
         if (!e.StagingItem.Input.Handled)
         {
             InputReportEventArgs inputReportEventArgs = e.StagingItem.Input as InputReportEventArgs;
             if (inputReportEventArgs != null)
             {
                 RawAppCommandInputReport rawAppCommandInputReport = inputReportEventArgs.Report as RawAppCommandInputReport;
                 if (rawAppCommandInputReport != null)
                 {
                     IInputElement commandTarget = e.StagingItem.Input.OriginalSource as IInputElement;
                     if (commandTarget != null)
                     {
                         RoutedCommand command = GetRoutedCommand(rawAppCommandInputReport.AppCommand);
                         if (command != null)
                         {
                             // Send the app command to the tree to be handled by UIElements and ContentElements
                             // that will forward the event to CommandManager.
                             CommandDeviceEventArgs args = new CommandDeviceEventArgs(this, rawAppCommandInputReport.Timestamp, command);
                             args.RoutedEvent = CommandDeviceEvent;
                             args.Source = commandTarget;
                             e.PushInput(args, e.StagingItem);
                         }
                     }
                 }
             }
         }
     }
     else if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyUpEvent ||
              e.StagingItem.Input.RoutedEvent == Mouse.MouseUpEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.GotKeyboardFocusEvent ||
              e.StagingItem.Input.RoutedEvent == Keyboard.LostKeyboardFocusEvent)
     {
         CommandManager.InvalidateRequerySuggested();
     }
 }