如何禁用 Ctrl+1 的默认 RichTextBox 命令?
Snoop 显示该命令是“ApplySingleSpace”,但是当我尝试通过 这篇文章。像这样:
<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
中。
我缺少什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用自定义命令覆盖 KeyBinding 来执行您想要的操作而不是尝试以某种方式禁用它怎么样?
取自此问题。
How about overwriting that KeyBinding with a custom command that does what you want instead of trying to somehow disable it?
Taken from this question.
使用此答案中的代码
如何在 C# 中以编程方式生成按键事件?
除了您想要由 richtextbox 处理的事件之外,重新触发 PreviewKeyDown 上的所有事件似乎对我有用。 (我只需要 Ctrl-C 进行复制)。当然,如果您需要的话,您可以做到只重新触发 Ctrl-1。
Using the code from this answer
How can I programmatically generate keypress events in C#?
to refire all events on PreviewKeyDown other than those you want handled by the richtextbox seems to work for me. (I only need Ctrl-C for copy). Of course you could make it so it only refires Ctrl-1 if that's what you need.
不如尝试用手势来代替......
What about trying with the gesture instead...