TextRange(TextPointer, TextPointer) Konstruktor

Definicja

Inicjuje TextRange nowe wystąpienie klasy, przyjmując dwa określone TextPointer pozycje jako pozycje początkowe i końcowe dla nowego zakresu.

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)

Parametry

position1
TextPointer

Stałe położenie kotwicy oznaczające jeden koniec zaznaczenia użytego do utworzenia nowego TextRangeelementu .

position2
TextPointer

Pozycja wymienna, która oznacza drugi koniec zaznaczenia użytego do utworzenia nowego TextRangeelementu .

Wyjątki

Występuje, gdy position1 i position2 nie są umieszczone w tym samym dokumencie.

Występuje, gdy position1 wartość lub position2 ma wartość null.

Przykłady

W poniższym przykładzie pokazano użycie konstruktora 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

Uwagi

Element A TextRange jest tworzony na podstawie zaznaczenia między dwoma pozycjami wskazanymi przez program TextPointers. Jedno z tych pozycji (wskazane przez position1) jest stałe w odniesieniu do zaznaczenia, podczas gdy drugie położenie (wskazane przez position2) jest wymienne. Jest to podobne do zachowania wyboru dokonanego przez użytkownika za pomocą myszy lub klawiatury.

Rzeczywiste końce nowego TextRange elementu można dostosować tak, aby odpowiadały wszelkim heurystyce wyboru, które mają zastosowanie do dokumentu zawierającego nowy TextRangeelement .

Dotyczy