TextRange(TextPointer, TextPointer) Konstruktor

Definition

Initialisiert eine neue Instanz der TextRange Klasse, wobei zwei angegebene Positionen als Anfangs- und Endpositionen für den neuen Bereich verwendet TextPointer werden.

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 Verankerungsposition, die ein Ende der Auswahl markiert, die verwendet wird, um das neue TextRangezu bilden.

position2
TextPointer

Eine verschiebbare Position, die das andere Ende der Auswahl markiert, die zum Bilden des neuen TextRangemarkiert wird.

Ausnahmen

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

Tritt auf, wenn position1 oder position2 ist null.

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 TextPointers angegeben werden. Eine dieser Positionen (angegeben durch position1) ist in Bezug auf die Auswahl fest, während die andere Position (angegeben durch position2) bewegliche ist. Dies ähnelt dem Verhalten einer Auswahl durch einen Benutzer, der die Maus oder Tastatur verwendet.

Die tatsächlichen Enden des neuen TextRange können an alle Auswahl heuristiken angepasst werden, die auf das Dokument anwendbar sind, das das neue TextRangeenthält.

Gilt für: