TextRange(TextPointer, TextPointer) Constructor

Definición

Inicializa una nueva instancia de la clase TextRange, que toma dos posiciones TextPointer especificadas como las posiciones inicial y final para el nuevo intervalo.

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)

Parámetros

position1
TextPointer

Una posición de anclaje fija que marca un extremo de la selección utilizada para formar el nuevo TextRange.

position2
TextPointer

Una posición movible que marca el otro extremo de la selección utilizada para formar el nuevo TextRange.

Excepciones

Se produce cuando position1 y position2 no se colocan dentro del mismo documento.

Se produce cuando el objeto position1 o position2 es null.

Ejemplos

En el ejemplo siguiente se muestra el uso del TextRange constructor .

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

Comentarios

Se TextRange forma a partir de una selección entre dos posiciones indicadas por TextPointers. Una de estas posiciones (indicada por position1) se fija con respecto a la selección, mientras que la otra posición (indicada por position2) es móvil. Esto es similar a cómo se comporta una selección realizada por un usuario mediante el mouse o el teclado.

Los extremos reales del nuevo TextRange se pueden ajustar para que coincidan con cualquier heurística de selección aplicable al documento que contenga el nuevo TextRange.

Se aplica a