Run element is an inline-level flow content element intended to contain a run of formatted text.
The code in Example 1 creates a Run element and adds it to a Paragraph.
Example 1: Create and add a run to a paragraph
Run run = new Run(document); paragraph.Inlines.Add(run);
The parent Paragraph should belong to the same document that is passed to the constructor of the Run.
You can add a run at a specific index in the Inlines collection of a paragraph using the Insert() method. Example 2 demonstrates how to add a run at the beginning of a paragraph.
Example 2: Create and add a run at a specific index of a paragraph's Inlines collection
Run run = new Run(document); paragraph.Inlines.Insert(0, run);
You can also use the AddRun() method of the Inlines collection of a paragraph. The method creates a new Run instance, adds it to the container and returns it:
Example 3: Create and add a run to a paragraph
// Adds an empty run. Run run1 = paragraph.Inlines.AddRun(); // Adds a run and sets the text to the text property. Run run2 = paragraph.Inlines.AddRun("The text.");
Inserting text in the document can also be achieved with the RadFlowDocumentEditor class:
Example 4: Insert a run using RadFlowDocumentEditor
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(GetDocument()); // Adds a new run to the document. Run run1 = editor.InsertText("First run "); // Adds a new run and starts a new paragraph. Run run2 = editor.InsertLine("Second run");
The Run exposes several properties that allow you to customize how it is rendered and formatted. A part of these properties are Style properties and some of the values represent a themable object.
Style properties are properties that can be inherited from a style. For more information about styles see this article.
Themable objects are objects that can be inherited from a theme. For more information about themes check this article.
Properties: Retrieves all CharacterProperties for this element. For more information about the CharacterProperties see this article.
Text: Specifies the text for the run.
FlowDirection: Represents the flow direction of the run:
- LeftToRight: Indicates that the text should flow from left to right.
- RightToLeft: Indicates that the text should flow from right to left.
StyleId: Represents the ID of the style that is applied to this run.
FontFamily: Specifies the font family that is used to render the text. This is a Style property. The value is themable object.
FontSize: Specifies the size of the font. This is a style property. The value is in device independent pixels (1/96 inch).
Shading: Represents the shading applied to the run. It is a composite object and is read-only. You can obtain the following properties from it:
- BackgroundColor: Specifies the background color for the shading. This is a Style property. The value is themable object.
- PatternColor: Specifies the pattern color for the shading. This is a Style property. The value is themable object.
- Pattern: Specifies the pattern which is used to lay the pattern color over the background color for the shading. This is a Style property.
FontStyle: Specifies the font style. This is a Style property.
FontWeight: Specifies the font weight. This is a Style property.
ForegroundColor: Specifies the foreground color. This is a Style property. The value is themable object.
HighlightColor: Specifies the highlight color. This is a Style property.
BaselineAlignment: Specifies how the baseline is positioned on the vertical axis, relative to the established baseline for text. This is a Style property.
Strikethrough: Specifies if the text is stroked trough. This is a Style property.
Underline: Specifies the underline for the run. It is composite object and is read-only. You can obtain the following properties from it:
- Color: Indicates the underline color. This is a Style property.
- Pattern: Indicates the underline pattern. This is a Style property.