3

I handle commands inside a RoutedCommand class that implements RoutedUICommand. This would help me to block or override a command by checking their CanExecute and Execute if needed. I can override EditingCommand, ApplicationCommand, etc.. One of the command that I cannot even handle is Ctr + Spacebar. Is it a MediaCommand or some other types that I cannot find? I guess it is been handled somewhere else, and that's why I cannot control it.

paradisonoir
  • 2,892
  • 9
  • 30
  • 41

2 Answers2

2

You can create your own custom command or you can simply add new gesture for predefined command, e.g.:

public Window1()
    {
        InitializeComponent();
        ApplicationCommands.Find.InputGestures.Add(new KeyGesture(Key.Space, ModifierKeys.Control));
        CommandBinding commandBinding = new CommandBinding(ApplicationCommands.Find, myCommandHandler);
        this.CommandBindings.Add(commandBinding);
    }

    private void myCommandHandler(object sender, ExecutedRoutedEventArgs args)
    {
        MessageBox.Show("Command invoked!");
    }
Hun1Ahpu
  • 3,315
  • 3
  • 28
  • 34
  • Your solution works. However my problem was when I had a mediaplayer playing and later on I figured out that the control is handling some level higher. – paradisonoir Nov 22 '10 at 21:56
0

I have not much experience using WPF commands, but try creating your own custom commands for Ctrl and Spacebar.

See this tutorial: http://www.switchonthecode.com/tutorials/wpf-tutorial-command-bindings-and-custom-commands

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415