开发者

WPF Richtextbox and keyboard shortcuts

I'm implementing a WPF application with a richtextbox for German users. They want to use their "normal" keyboard shortcuts to do some basic formatting: bold, italic, underline.

In English, the shortcuts CTRL+B, CTRL+I, and CTRL+U are working in the Richtextbox.

However the "normal" German shortcuts are CTRL+SHIFT+F (Fett = Bold), CTRL+SHIFT+K (Kursiv = Italic) and CTRL+SHIFT+U (for Underline). When running the WPF (.net 4.0) application on a German Windows machine (Windows 7), the Richttextbox is not reacting to these shortcuts and also the "English" shortcuts are not working. Only CTRL+SHIFT+F is doing something, but does it wrong: it makes the selected text Italic, not Bold.

Any suggestions on how to fix this? Is there a way to define the shortcut mappings explicitly for the RichTextBox? Any other suggestions? Is this开发者_如何学JAVA a bug?

Kind regards,

Robbie De Sutter


I think you can disable command binding you don't want to allow with:

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

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

You could then create custom command bindings for what you want to allow using something like what is shown here: http://www.switchonthecode.com/tutorials/wpf-tutorial-command-bindings-and-custom-commands

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜