Editar

Compartir a través de


TextRange.Text Property

Definition

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

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

Property Value

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

Exceptions

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

Examples

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;
}
' This method returns a plain text representation of a specified FlowDocument.
Private Function GetTextFromFlowDocument(ByVal flowDoc As FlowDocument) As String
    ' Create a new TextRanage that takes the entire FlowDocument as the current selection.
    Dim flowDocSelection As 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
End Function

Remarks

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.

Applies to