New to Telerik UI for WPF? Download free 30-day trial

Commands

RadSyntaxEditor exposes its functionality through various commands that can be executed on its behalf. All commands can be accessed through the Commands property of the control. Here's a full list of the available commands:

  • OpenFindDialogCommand—Opens the find dialog. If there is any selected text, it is loaded in the search textbox.
  • CloseFindDialogCommand—Closes the find dialog.
  • NavigateNextMatchCommand—Navigates to the next matched text in the editor and selects it. If the match is contained in a folded region, it is unfolded. Takes as a parameter the search text.
  • NavigatePreviousMatchCommand—Navigates to the previous matched text in the editor and selects it. If the match is contained in a folded region, it is unfolded. Takes as a parameter the search text.
  • HighlightAllMatchesCommand—Tries to highlight all span matches via all registered TextSearchHighlightTaggers. Takes as a parameter the search text.
  • CodeCompletionCommand—Shows the IntelliSense code completion dialog.
  • CutCommand—Cuts the selected text or the current line if there is no selection.
  • CopyCommand—Copies the selected text or the current line if there is no selection.
  • PasteCommand—Pastes over the selected text or at the caret's position if there is no selection.
  • BackspaceCommand—Deletes the selected text or the last character before the caret if there is no selection.
  • DeleteCommand—Deletes the selected text or the first character after the caret if there is no selection.
  • DeleteFullLineCommand—Deletes the full line on which the cursor currently is.
  • DeleteWordToLeftCommand—Deletes the word to the left of the cursor.
  • DeleteWordToRightCommand—Deletes the word to the right of the cursor.
  • IndentCommand—Indents the selected text or the current line if there is no selection.
  • UnindentCommand—Unindents the selected text or the current line if there is no selection.
  • MoveCaretCommand—Moves the caret depending on the CaretMovementType parameter which is passed.
  • RedoCommand—Redoes the last undo action.
  • UndoCommand—Undoes the last action.
  • SelectAllCommand—Selects all the text.
  • ToggleInsertModeCommand—Toggles the insert mode.

The following example demonstrates how to select and delete the first occurrence of the "Telerik" word from the loaded text in code-behind and in XAML:

Use commands in code-behind

this.syntaxEditor.Commands.NavigateNextMatchCommand.Execute("Telerik"); 
this.syntaxEditor.Commands.DeleteCommand.Execute(null); 

Use commands in XAML

<telerik:RadSyntaxEditor x:Name="syntaxEditor" /> 
<telerik:RadButton Content="Select Next Match" Command="{Binding Commands.NavigateNextMatchCommand, ElementName=syntaxEditor}" CommandParameter="Telerik" /> 
<telerik:RadButton Content="Delete" Command="{Binding Commands.DeleteCommand, ElementName=syntaxEditor}" /> 

Managing Commands

RadSyntaxEditor allows you to register and unregister its commands. To do so, you can utilize the RegisterCommand and UnregisterCommand methods of the KeyBindings property of the RadSyntaxEditor control.

The following examples show how to register and unregister the CodeCompletionCommand:

Register a command

SyntaxEditorDelegateCommand codeCompletionCommand = (SyntaxEditorDelegateCommand)this.syntaxEditor.Commands.CodeCompletionCommand; 
this.syntaxEditor.KeyBindings.RegisterCommand(codeCompletionCommand, Key.Enter, ModifierKeys.Control); 
Dim codeCompletionCommand As SyntaxEditorDelegateCommand = CType(Me.syntaxEditor.Commands.CodeCompletionCommand, SyntaxEditorDelegateCommand) 
Me.syntaxEditor.KeyBindings.RegisterCommand(codeCompletionCommand, Key.Enter, ModifierKeys.Control) 

Unregister a command

SyntaxEditorDelegateCommand codeCompletionCommand = (SyntaxEditorDelegateCommand)this.syntaxEditor.Commands.CodeCompletionCommand; 
this.syntaxEditor.KeyBindings.UnregisterCommand(codeCompletionCommand); 
Dim codeCompletionCommand As SyntaxEditorDelegateCommand = CType(Me.syntaxEditor.Commands.CodeCompletionCommand, SyntaxEditorDelegateCommand) 
Me.syntaxEditor.KeyBindings.UnregisterCommand(codeCompletionCommand) 

Registering and unregistering commands would require the RadSyntaxEditor control to be loaded. You can utilize the RegisterCommand and UnregisterCommand methods in the Loaded event of the control.

See Also

In this article