Search code examples
wpfrichtextboxcommandbinding

How can I disable the default RichTextBox command for Ctrl+1?


Snoop shows that the command is "ApplySingleSpace", but when I try disabling it via the method described in this article . Like this:

<RichTextBox.CommandBindings>
     <CommandBinding 
       Command="ApplySingleSpace" 
       CanExecute="BlockTheCommand"/>
   </RichTextBox.CommandBindings>

.

  private void BlockTheCommand(object sender,
     CanExecuteRoutedEventArgs e)
   {
     e.CanExecute = false;
     e.Handled = true;
   }

My app crashes because there is no ApplySingleSpace command. ApplySingleSpace is not in the EditingCommands either.

What am I missing?


Solution

  • Unfortunately that will not work for me. The reason I am trying to disable the command is that I have a KeyBinding in a higher nested view that is not firing because the CTRL+1 gesture is being swallowed by the richtextbox which has keyboardfocus.

    How about overwriting that KeyBinding with a custom command that does what you want instead of trying to somehow disable it?

    <RichTextBox.InputBindings>
        <KeyBinding Command="local:YourCommands.Cmd1" Gesture="CTRL+1" />
    <RichTextBox.InputBindings>
    

    Taken from this question.