忽略 WPF RichTextBox 中的 Ctrl-L

Ada*_*ane 5 wpf keyboard-shortcuts richtextbox

如何从 WPF RichTextBoxCtrl中忽略/阻止/删除-键盘快捷键?L

现在,这绑定到AlignLeft EditingCommand。我想在 RichTextBox 中使用此键盘快捷键进行其他操作(删除行)。

我目前正在处理 keyDown 事件,但是Ctrl-L从未成功。换句话说,我可以响应Ctrl- H,例如,没问题,但是Ctrl-L已经被控件吞噬了。

    private void richTextBoxMain_KeyDown (object sender, KeyEventArgs e)
    {

        if ( Keyboard.IsKeyDown(Key.LeftCtrl))
        {
            if (e.Key == Key.L)
            {
                 // never gets here.
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

key*_*rdP 5

将其添加到您的页面加载方法中(或合适的地方)

KeyBinding keyBinding = new KeyBinding(ApplicationCommands.NotACommand, Key.L, 
                                                         ModifierKeys.Control);
richTextBoxMain.InputBindings.Add(keyBinding);
Run Code Online (Sandbox Code Playgroud)

这将阻止CTRL + L调用它通常执行的命令(由于枚举NotACommand)。您的方法中当前的代码KeyDown现在应该可以工作。