TextRange.Text Property


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

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

public string Text { get; set; }

Property Value

Type: System.String

A string containing the plain text contents of the current selection.

Exception Condition

Occurs when an attempt is made to set this property to null.

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

New line characters and paragraph breaks are treated as equivalent with respect to this property. Any types of content breaks present in the current selection are converted to new lines when this property is read.

The following example demonstrates the use of the Text property.

// This method returns a plain text representation of a specified FlowDocument.
string GetTextFromFlowDocument(FlowDocument flowDoc)
     // Create a new TextRanage that takes the entire FlowDocument as the current selection.
     TextRange flowDocSelection = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);

     // Use the Text property to extract a string that contains the unformatted text contents 
     // of the FlowDocument.
     return flowDocSelection.Text;

.NET Framework
Available since 3.0
Return to top