In the recently released Q3 2010 we introduced some more cool UI additions to RadRichTextBox, including SelectionMiniToolBar and ContextMenu.


SelectionMiniToolBar is a floating toolbar that appears next to the current position after making a selection with the mouse in the document. It contains some useful commands for formatting text:


As RadRichTextBox loads the default SelectionMiniToolBar using MEF, it can be completely replaced with a custom one. This can be done as easy as with the other RadRichTextBox dialogs by implementing the interface ISelectionMiniToolBar and marking the class that implements it with the CustomSelectionMiniToolBarAttribute attribute. The technique was also described in greater details in this blog post.


The ContextMenu is showed on right click over the RadRichTextBox, and contains some context specific commands arranged in groups – there are groups for spellchecking (1), clipboard (2), table editing (3) and text editing commands (4) as shown here:


Besides replacing the default ContextMenu (by implementing IContextMenu and marking it with CustomContextMenuAttribute), here are some more customization approaches.

The first one involves subscribing to the Showing event of the default ContextMenu. Showing is not part of the IContextMenu interface, so in order to subscribe to it we need a cast to the ContextMenu class (the default implementation of IContextMenu in Telerik.Windows.Documents.RadRichTextBoxUI.dll):

ContextMenu contextMenu = (ContextMenu)this.radRichTextBox.ContextMenu;
contextMenu.Showing +=


In the event handler we can check the context relevant items and add some RadMenuItems if needed:

private void ContextMenu_Showing(object sender, ContextMenuEventArgs e)
    // First check the context - if caret is in table, add our item
    if (this.radRichTextBox.Document.CaretPosition.IsPositionInsideTable)
        RadMenuItem makeCellYellowMenuItem = new RadMenuItem() { Header = "Make Cell Yellow" };
        makeCellYellowMenuItem.Click +=

        ContextMenuGroup customContextMenuGroup = new ContextMenuGroup();


private void MakeCellYellowMenuItem_Click(object sender, RadRoutedEventArgs e)
    TableCell currentCell = this.radRichTextBox.Document.CaretPosition.GetCurrentTableCellBox().AssociatedTableCell;
    currentCell.Background =

The second approach is more suitable when you need to reuse the customization across several RadRichTextBox instances/applications. Here we can either implement the IContextMenuContentBuilder interface or derive from the ContextMenuContentBuilder class and override some of its protected methods which are responsible for the creation of each context menu group:


Now you can simply assign the instance of your class to the ContentBuilder property of the context menu:

ContextMenu contextMenu = (ContextMenu)this.radRichTextBox.ContextMenu;
contextMenu.ContentBuilder =
new CustomContextMenuContentBuilder(this.radRichTextBox);


And of course, for those of you who don’t need additional UI pop-ups, these can be disabled by setting IsSelectionMiniToolBarEnabled and IsContextMenuEnabled properties of the RadRichTextBox to false.

About the Author

Borislav Ivanov

is a software developer in the Telerik XAML team, working mainly on RadRichTextBox, and occasionally supporting team’s build infrastructure. He is passionate about his work, but also loves his vacations, when he can be found backpacking distant locations in Europe, Africa and Asia with his girlfriend.

Related Posts


Comments are disabled in preview mode.