Keyboard Support
Telerik RichTextBox for WPF supports the commanding mechanism in WPF. There are default key-bindings defined for the most widely used commands.
Action | Hotkey |
---|---|
Open new document | Ctrl+N |
Open existing document | Ctrl+O |
Save | Ctrl+S |
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 |
IncrementFontSize | Ctrl+Shift+OemPeriod |
DecrementFontSize | Ctrl+Shift+OemComma |
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 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>
Example 2: Namespace definition
xmlns:telerikDocs="clr-namespace:Telerik.Windows.Documents.RichTextBoxCommands;assembly=Telerik.Windows.Documents"
Example 3: Disable the shortcut for creating a new document in code-behind
this.radRichTextBox.RegisteredApplicationCommands.Remove(System.Windows.Input.ApplicationCommands.New);
By default, the tab symbol can always be inserted with Ctrl+Tab shortcut.
By default, the Tab shortcut is bound to the TabForward command - a command with more complex, context-dependent behavior. You can remap the shortcut to the InsertText command with the tab symbol as a parameter.
Example 4: Remap the shortcut to different command
<telerik:RadRichTextBox >
<telerik:RadRichTextBox.InputBindings>
<KeyBinding Gesture="Tab" Command="telerikDocs:RichTextBoxCommands.InsertText" CommandParameter="	" />
</telerik:RadRichTextBox.InputBindings>
</telerik:RadRichTextBox>
Example 5: Customize command behavior through its parameters
<telerik:RadRichTextBox.InputBindings>
<KeyBinding Gesture="Tab" Command="telerikDocs:RichTextBoxCommands.TabForward" CommandParameter="InsertTabSymbol, ChangeParagraphListLevel, ChangeParagraphLeftIndent, NavigateInTable, AppendTableRow" />
</telerik:RadRichTextBox.InputBindings>
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("€");
}
};