Text Property
Collapse the table of content
Expand the table of content

TextSelection.Text Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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 "";
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft