This documentation is archived and is not being maintained.

TextRange.Text Property

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

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public string Text { get; set; }
<object Text="string" .../>

Property Value

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

ExceptionCondition
ArgumentNullException

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

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: