Share via


TextRange(TextPointer, TextPointer) Konstruktor

Definition

Initialisiert eine neue Instanz der TextRange-Klasse mit zwei angegebenen TextPointer-Positionen als Anfangs- und Endpositionen für den neuen Bereich.

public:
 TextRange(System::Windows::Documents::TextPointer ^ position1, System::Windows::Documents::TextPointer ^ position2);
public TextRange (System.Windows.Documents.TextPointer position1, System.Windows.Documents.TextPointer position2);
new System.Windows.Documents.TextRange : System.Windows.Documents.TextPointer * System.Windows.Documents.TextPointer -> System.Windows.Documents.TextRange
Public Sub New (position1 As TextPointer, position2 As TextPointer)

Parameter

position1
TextPointer

Eine feste Ankerposition, die ein Ende der Auswahl für den neuen TextRange markiert.

position2
TextPointer

Eine verschiebbare Ankerposition, die das andere Ende der Auswahl für den neuen TextRange markiert.

Ausnahmen

Tritt auf, wenn position1 und position2 nicht innerhalb desselben Dokuments positioniert sind.

Tritt auf, wenn position1 oder position2 den Wert null hat.

Beispiele

Im folgenden Beispiel wird die Verwendung des TextRange Konstruktors veranschaulicht.

// 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

Hinweise

A TextRange wird aus einer Auswahl zwischen zwei Positionen gebildet, die von TextPointern angegeben werden. Eine dieser Positionen (angegeben durch position1) ist in Bezug auf die Auswahl festgelegt, während die andere Position (durch position2) verschiebbar ist. Dies ähnelt dem Verhalten einer Auswahl durch einen Benutzer mit der Maus oder Tastatur.

Die tatsächlichen Enden des Neuen TextRange können angepasst werden, um allen Auswahl-Heuristiken zu entsprechen, die auf das Dokument anwendbar sind, das das neue TextRangeenthält.

Gilt für