Keyboard Support

Telerik RichTextBox for Silverlight supports commands in a way that is similar to the commanding mechanism in WPF. It is only natural that some of these commands be triggered on key combinations. There are default key-bindings defined for the most widely used commands.

Note that the browser could handle some of the shortcuts and some of them cannot be even enabled. RadRichTextBox is not capable of modifying this behavior as it is up to the browser.

 
Action Hotkey
Open new document Ctrl+N
Open existing document Ctrl+O
Save Ctrl+S
Print Ctrl+P
Copy Ctrl+C
Paste Ctrl+V
Cut Ctrl+X
Delete Delete
Delete previous symbol Back, Ctrl+Back, Shift+Back
Undo Ctrl+Z
Redo Ctrl+Y
InsertLineBreak Shift+Enter
InsertPageBreak Ctrl+Enter
InsertColumnBreak Ctrl+Enter, Shift+Enter
ToggleBold Ctrl+B, Ctrl+Shift+B
ToggleItalic Ctrl+I, Ctrl+Shift+I
ToggleSuperscript Ctrl+'+'
ToggleSubscript Ctrl+Shift+'+'
ToggleUnderline Ctrl+U
ToggleFormattingSymbols Ctrl+D8, Shift+D8
ClearFormatting Ctrl+Space
CopyFormatting Ctrl+Shift+C
PasteFormatting Ctrl+Shift+V
CancelFormatPainter or ExitHeaderFooterEditMode, depending on the current editing context Esc
ChangeTextAlignment with parameter RadTextAlignment.Justify Ctrl+J
ChangeTextAlignment with parameter RadTextAlignment.Right Ctrl+R
ChangeTextAlignment with parameter RadTextAlignment.Left Ctrl+L
ChangeTextAlignment with parameter RadTextAlignment.Center Ctrl+E
TabForward Tab
TabBackward Shift+Tab
InsertText with parameter "\t" Ctrl+Tab
Insert non-breaking space Ctrl+Space
SelectAll Ctrl+A
MoveCaret with parameter MoveCaretDirections.Previous Left Arrow
MoveCaret with parameter MoveCaretDirections.Next Right Arrow
MoveCaret with parameter MoveCaretDirections.PreviousWord Ctrl+Left Arrow
MoveCaret with parameter MoveCaretDirections.NextWord Ctrl+Right Arrow
MoveCaret with parameter MoveCaretDirections.Up Upper Arrow
MoveCaret with parameter MoveCaretDirections.Down Down Arrow
MoveCaret with parameter MoveCaretDirections. ParagraphStart Ctrl+Upper Arrow
MoveCaret with parameter MoveCaretDirections. ParagraphEnd Ctrl+Down Arrow
MoveCaret with parameter MoveCaretDirections.Home Home
MoveCaret with parameter MoveCaretDirections.DocumentStart. This moves the caret at the first position of the document. Ctrl+Home
MoveCaret with parameter MoveCaretDirections.End End
MoveCaret with parameter MoveCaretDirections.DocumentEnd Ctrl+End
MoveCaret with parameter MoveCaretDirections.PageUp PageUp
MoveCaret with parameter MoveCaretDirections.PageDown PageDown
ShowSpellCheckingDialog F7
ShowFindReplaceDialog Ctrl+F
ShowFontPropertiesDialog Ctrl+D
ShowInsertHyperlinkDialog Ctrl+K

Now these key bindings can be overridden and customized to the liking of the user. What is more, new bindings can be added to both the Commands exposed through the RichTextBoxCommands class or to user-defined ones in a quite straight-forward way. This is how it can be done in XAML:

Example 1: Customize InputBindings

<telerik:RadRichTextBox Grid.Row="1" Name="editor"> 
    <telerik:CommandManager.InputBindings> 
        <telerik:InputBindingCollection> 
            <!-- Bind Spell Checking to Ctrl+Shift+S --> 
            <telerik:KeyBinding Gesture="Ctrl+Shift+S" Command="RichTextBoxCommands.ShowSpellCheckingDialog"/> 
            <!-- Stop Toggle Bold on Ctrl+Shift+B --> 
            <telerik:KeyBinding Gesture="Ctrl+Shift+B"/> 
            <!-- Re-map Ctrl+Space from Clear Formating to ShowManageBookmarksDialog --> 
            <telerik:KeyBinding Gesture="Ctrl+Space" Command="RichTextBoxCommands.ShowManageBookmarksDialog"/> 
        </telerik:InputBindingCollection> 
    </telerik:CommandManager.InputBindings> 
</telerik:RadRichTextBox> 

You can check the Simulate Watermark SDK example which demonstrates how you can modify the InputBindings collection of RadRichTextBox in code-behind.

Sometimes overriding the key bindings does not provide sufficient support, as depending on the language and the keyboard, different ModifierKeys are registered. For example, pressing RightAlt causes Control and Alt to be sent as arguments to the PreviewKeyDown event. Thus, RightAlt+E triggers a formatting command for paragraph alignment instead of inputting the ę character. In that case, you can handle the PreviewEditorKeyDown event in the following way:

Example 6: Customizing the behavior of a keyboard combination

  this.radRichTextBox.PreviewEditorKeyDown += (sender, args) => 
     { 
         if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt) && Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && args.Key == Key.E) 
         { 
             args.SuppressDefaultAction = true; 
             args.OriginalArgs.Handled = true; 
             this.radRichTextBox.Insert("€"); 
         } 
     }; 

See Also

In this article