Export (0) Print
Expand All

TextSelection.Text Property


Gets or sets the plain text contents of the current selection.

Namespace:  System.Windows.Documents
Assembly:  System.Windows (in System.Windows.dll)

public string Text { get; set; }

Property Value

Type: System.String
A string that contains the plain text contents of the current selection.

Use this property to extract the plain text content in the current selection, regardless of any formatting that may be present.

In this property, new line characters and paragraph breaks are treated as equivalent. Any content breaks in the current selection are converted to new lines when this property is read.

The following code shows a method that takes a RichTextBox named RTB and a TextPointer named pointer. It uses the Text property to return the string in RTB that is represented by pointer.

private string GetCurrentChar(RichTextBox RTB, TextPointer pointer, LogicalDirection direction)
    TextPointer nextPointer = pointer.GetNextInsertionPosition(direction);
    if (nextPointer != null)
        RTB.Selection.Select(pointer, nextPointer);
        if (RTB.Selection.Text.Length != 0)
            return RTB.Selection.Text[0].ToString();
    return "";


Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2015 Microsoft