Edit this page

Keyboard Support

Telerik RichTextBox for WPF supports the commanding mechanism in WPF. There are default key-bindings defined for the most widely used commands, namely:

 
Action Hotkey
Copy Ctrl+C
Paste Ctrl+V
Cut Ctrl+X
Delete Delete
Undo Ctrl+Z
Redo Ctrl+Y
InsertLineBreak Shift+Enter
InsertPageBreak Ctrl+Enter
ToggleBold Ctrl+B, Ctrl+Shift+B
ToggleItalic Ctrl+I, Ctrl+Shift+I
ToggleSuperscript Ctrl+'+'
ToggleSubscript Ctrl+Shift+'+'
ToggleUnderline Ctrl+U
ClearFormatting Ctrl+Space
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
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 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
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:

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

Please note that in the above code snippet the telerikDocs namespace is defined as follows:

xmlns:telerikDocs="clr-namespace:Telerik.Windows.Documents.RichTextBoxCommands;assembly=Telerik.Windows.Documents"

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:

  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

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy