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

Working with Content Controls Programmatically

This article shows some examples of how you can insert content controls or access existing and modify their properties from the code. In RadRichTextBox, the content controls are marked with annotations and you can manipulate them as such. Detailed information is available in the Manipulating Annotations topic.

Manipulate Existing Content Controls

Get the Content Controls

The content controls can be retrieved by using the GetAnnotationMarkersOfType method.

Example 1: Get all content controls

IEnumerable<SdtRangeStart> content_controls = this.radRichTextBox.Document.GetAnnotationMarkersOfType<SdtRangeStart>(); 
foreach (SdtRangeStart item in content_controls) 
    Console.WriteLine("Type: {0} ID:{1}", item.SdtProperties.Type, item.SdtProperties.ID); 

Set Content Controls Properties

This example show how one can iterate the items and add an item to to a existing ComboBox content control.

Example 2: Adding items to a ComboBox or a DropDownList

foreach (SdtRangeStart item in content_controls) 
    if (item.SdtProperties.Type == SdtType.ComboBox) 
        ComboBoxProperties properties = item.SdtProperties as ComboBoxProperties; 
        ListItem newItem = new ListItem(); 
        newItem.DisplayText = "New Item Text"; 

Insert New Content Controls

New content controls can be inserted trough one of the overloads of the InsertStructuredDocumentTag method accessible from RadRichTextBox and RadDocumentEditor:

Example 3: Inserting a content control

// OR 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextBox.Document); 

Example 4: Inserting a content control using content control type

// OR 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextBox.Document); 

Example 5: Inserting a content control using content control properties

SdtProperties sdtProperties = new SdtProperties(SdtType.RichText) 
    Alias = "AliasName", 
    Lock = Lock.SdtContentLocked, 
// OR 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextBox.Document); 

See Also

In this article
Not finding the help you need? Improve this article