Язык

TextRange(TextPointer, TextPointer) Конструктор

Определение

Инициализирует новый экземпляр класса TextRange, принимая две указанные TextPointer позиции в качестве начальной и конечной позиций для нового диапазона.

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)

Параметры

position1
TextPointer

Фиксированная позиция привязки, которая помечает один конец выделенного фрагмента, используемый для формирования нового TextRange.

position2
TextPointer

Перемещаемая позиция, которая помечает другую часть выделенного фрагмента, используемую для формирования нового TextRange.

Исключения

Происходит, когда position1 и position2 не размещаются в одном документе.

Происходит, когда position1 или position2 есть null.

Примеры

В следующем примере показано использование конструктора TextRange .

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

Комментарии

Объект TextRange формируется из выделения между двумя позициями, указанными TextPointers. Одна из этих позиций (указанная position1на) фиксирована относительно выделения, а другая позиция (указанная position2на) перемещается. Это похоже на то, как выполняется выбор, сделанный пользователем с помощью мыши или клавиатуры.

Фактические концы нового TextRange могут быть скорректированы, чтобы соответствовать любым эвристикам выбора, применимым к документу, который содержит новый TextRange.

Применяется к