TextRun Class
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
A text run is a sequence of characters sharing a single property set. Any change to the format, such as font style, foreground color, font family, or any other formatting effect, breaks the text run. The following example illustrates how changes in formatting to a text string results in a series of text runs—each text run has a common set of formatting properties.
Series of text runs that comprise a text string
The TextRun class is the root of a type hierarchy representing several types of text content processed by TextFormatter. Each class that is derived from TextRun represents a distinct type of text content.
| Class | Description |
|---|---|
| TextRun | Root of the hierarchy. Defines a group of characters that share the same set of character properties. |
| Defines a collection of character glyphs from a distinct physical typeface. | |
| Defines a type of text content in which measuring, hit testing, and drawing of the entire content is done as a distinct entity. An example of this type of content is a button in the middle of the line of text. | |
| Defines a line-break character code. | |
| Defines a paragraph-break character code. Derives from TextEndOfLine. | |
| Defines a segment break marker. | |
| Defines a range of non-visible characters. | |
| Defines the beginning of a modification scope. |
In the following example, an override for the GetTextRun method is implemented.
// Retrieve the next formatted text run for the text source. public override TextRun GetTextRun(int textSourceCharacterIndex) { // Determine whether the text source index is in bounds. if (textSourceCharacterIndex < 0) { throw new ArgumentOutOfRangeException("textSourceCharacterIndex", "Value must be greater than 0."); } // Determine whether the text source index has exceeded or equaled the text source length. if (textSourceCharacterIndex >= _text.Length) { // Return an end-of-paragraph indicator -- a TextEndOfParagraph object is a special type of text run. return new TextEndOfParagraph(1); } // Create and return a TextCharacters object, which is formatted according to // the current layout and rendering properties. if (textSourceCharacterIndex < _text.Length) { // The TextCharacters object is a special type of text run that contains formatted text. return new TextCharacters( _text, // The text store textSourceCharacterIndex, // The text store index _text.Length - textSourceCharacterIndex, // The text store length new CustomTextRunProperties()); // The layout and rendering properties } // Return an end-of-paragraph indicator if there is no more text source. return new TextEndOfParagraph(1); }
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.