Edit this page


The RadRichTextBox control exposes a full set of commands that that provide an alternative to its API methods, exposed through its Commands property. For each of the Formatting API methods there is a respective command. In order to use the command with an UI Element that supports commanding, you have to bind the Command property of the element to the respective command of the RadRichTextBox.

To see a list of all the commands exposed by RadRichTextBox, visit this topic.

Here is an example with a RadToggleButtonControl.

<telerik:RadToggleButton x:Name="BoldButton"
                            DataContext="{Binding Commands, ElementName=radRichTextBox}"
                            Command="{Binding ToggleBoldCommand}" />
<telerik:RadRichTextBox x:Name="radRichTextBox"
    <telerik:RadDocument LayoutMode="Paged" />

Now every time the button is clicked it will toggle the boldness of the current selection. The thing it won't do is to response to the current state of the selection. For example if the context of the caret is a bold text, the button won't get automatically toggled. In order to implement this behavior you have to handle the ToggleStateChanged event of the ToggleBoldCommand. Here is an example.

public CommandsSample()
    this.radRichTextBox.Commands.ToggleBoldCommand.ToggleStateChanged += this.ToggleBoldCommand_ToggleStateChanged;
public void ToggleBoldCommand_ToggleStateChanged( object sender, StylePropertyChangedEventArgs<bool> e )
    this.BoldButton.IsChecked = e.NewValue;
Public Sub New()
    Me.radRichTextBox.Commands.ToggleBoldCommand.ToggleStateChanged += Me.ToggleBoldCommand_ToggleStateChanged
End Sub
Public Sub ToggleBoldCommand_ToggleStateChanged(sender As Object, e As StylePropertyChangedEventArgs(Of Boolean))
    Me.BoldButton.IsChecked = e.NewValue
End Sub

Now the button will respond to the current state of the selection.

Rad Rich Text Box Features Commands 01

You can also use the functionality provided by the RadRichTextBoxRibbonUI class in order to get the event handling out of the box.

The RadRichTextBoxRibbonUI provides you with a fully predefined UI for the RadRichtextBox. To learn how to use it read this topic.

If you are building your UI manually ,for example using a RadRibbonView control, you have to only bind the command to the RadRichTextBoxRibbonUI.RichTextCommand attached property of the desired RadRibbonView control. Here is an example with a RadRibbonToggleButton.

<telerik:RadRibbonToggleButton x:Name="ItalicButton"
                                DataContext="{Binding Commands, ElementName=radRichTextBox}"
                                telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding ToggleItalicCommand}" />

The RadRibbonToggleButton will get automatically toggled whenever the context of the caret is an italic text.

More about the specific buttons introduced with RadRibbonView you can find here

Rad Rich Text Box Features Commands 02

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article