TextRange(TextPointer, TextPointer) Costruttore

Definizione

Inizializza una nuova istanza della TextRange classe , accettando due posizioni specificate TextPointer come posizioni iniziale e finale per il nuovo intervallo.

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)

Parametri

position1
TextPointer

Posizione fissa dell'ancoraggio che contrassegna una fine della selezione utilizzata per formare il nuovo TextRangeoggetto .

position2
TextPointer

Posizione mobile che contrassegna l'altra estremità della selezione utilizzata per formare il nuovo TextRangeoggetto .

Eccezioni

Si verifica quando position1 e position2 non sono posizionati all'interno dello stesso documento.

Si verifica quando position1 o position2 è null.

Esempio

Nell'esempio seguente viene illustrato l'uso del TextRange costruttore .

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

Commenti

Un TextRange oggetto viene formato da una selezione tra due posizioni indicate da TextPointers. Una di queste posizioni (indicata da position1) è fissa rispetto alla selezione, mentre l'altra posizione (indicata da position2) è mobile. Questo comportamento è simile al comportamento di una selezione effettuata da un utente che usa il mouse o la tastiera.

Le estremità effettive del nuovo TextRange oggetto possono essere modificate in modo che corrispondano a qualsiasi euristica di selezione applicabile al documento che contiene il nuovo TextRangeoggetto .

Si applica a