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.
Assembly: System.Windows (in System.Windows.dll)
Property Value
Type: System.StringA 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 ""; }