TextRange(TextPointer, TextPointer) Construtor

Definição

Inicializa uma nova instância da TextRange classe, assumindo duas posições especificadas TextPointer como início e fim para o novo 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

Uma posição fixa de âncora que marca uma extremidade da seleção usada para formar o novo TextRange.

position2
TextPointer

Uma posição móvel que marca a outra extremidade da seleção usada para formar o novo TextRange.

Exceções

Ocorre quando position1 e position2 não estão posicionados dentro do mesmo documento.

Ocorre quando position1 ou position2 é null.

Exemplos

O exemplo seguinte demonstra a utilização do TextRange construtor.

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

Observações

A TextRange é formado a partir de uma seleção entre duas posições indicadas pelos TextPointers. Uma destas posições (indicada por position1) é fixa em relação à seleção, enquanto a outra posição (indicada por position2) é móvel. Isto é semelhante ao comportamento de uma seleção feita por um utilizador usando rato ou teclado.

Os fins reais do novo TextRange podem ser ajustados para corresponder a quaisquer heurísticas de seleção que sejam aplicáveis ao documento que contém o novo TextRange.

Aplica-se a