如何禁用 Ctrl+1 的默认 RichTextBox 命令? [英] How can I disable the default RichTextBox command for Ctrl+1?

查看:60
本文介绍了如何禁用 Ctrl+1 的默认 RichTextBox 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Snoop 显示命令是ApplySingleSpace",但是当我尝试通过 这篇文章.像这样:

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;
   }

我的应用程序崩溃,因为没有 ApplySingleSpace 命令.ApplySingleSpace 也不在 EditingCommands 中.

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

我错过了什么?

推荐答案

不幸的是,这不适用于我.我试图禁用的原因命令是我有一个更高嵌套视图中的键绑定没有触发,因为 CTRL+1手势被吞了具有键盘焦点的富文本框.

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.

如何使用自定义命令覆盖 KeyBinding 来执行您想要的操作,而不是尝试以某种方式禁用它?

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>

摘自这个问题.

这篇关于如何禁用 Ctrl+1 的默认 RichTextBox 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆