TextPointer.GetNextContextPosition(LogicalDirection) Metodo

Definizione

Restituisce un puntatore al simbolo successivo nella direzione logica specificata.

public:
 System::Windows::Documents::TextPointer ^ GetNextContextPosition(System::Windows::Documents::LogicalDirection direction);
public System.Windows.Documents.TextPointer GetNextContextPosition (System.Windows.Documents.LogicalDirection direction);
member this.GetNextContextPosition : System.Windows.Documents.LogicalDirection -> System.Windows.Documents.TextPointer
Public Function GetNextContextPosition (direction As LogicalDirection) As TextPointer

Parametri

direction
LogicalDirection

Uno dei valori LogicalDirection che specifica la direzione logica nella quale cercare il simbolo successivo.

Restituisce

Oggetto TextPointer al simbolo successivo nella direzione richiesta, oppure null se l'oggetto TextPointer corrente delimita l'inizio o la fine del contenuto.

Esempio

Nell'esempio seguente viene illustrato un uso per questo metodo. L'esempio usa il metodo in combinazione con il GetNextContextPositionGetPointerContext metodo per attraversare ed estrarre i simboli in un oggetto specificato TextElement.

Anche se l'esempio può essere usato per estrarre una struttura XAML per il contenuto di un determinato TextElementoggetto , è destinato solo a scopi illustrativi e non deve essere usato nel codice di produzione. Vedere lo spazio dei nomi per un set completo di tipi progettati per l'uso e l'elaborazione System.Xml di XML.

// This method will extract and return a string that contains a representation of 
// the XAML structure of content elements in a given TextElement.        
string GetXaml(TextElement element)
{
    StringBuilder buffer = new StringBuilder();
 
    // Position a "navigator" pointer before the opening tag of the element.
    TextPointer navigator = element.ElementStart;

    while (navigator.CompareTo(element.ElementEnd) < 0)
    {
        switch (navigator.GetPointerContext(LogicalDirection.Forward))
        {
            case TextPointerContext.ElementStart : 
                // Output opening tag of a TextElement
                buffer.AppendFormat("<{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name);
                break;
            case TextPointerContext.ElementEnd :
                // Output closing tag of a TextElement
                buffer.AppendFormat("</{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name);
                break;
            case TextPointerContext.EmbeddedElement :
                // Output simple tag for embedded element
                buffer.AppendFormat("<{0}/>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name);
                break;
            case TextPointerContext.Text :
                // Output the text content of this text run
                buffer.Append(navigator.GetTextInRun(LogicalDirection.Forward));
                break;
        }
 
        // Advance the naviagtor to the next context position.
        navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
    } // End while.

    return buffer.ToString();
} // End GetXaml method.
' This method will extract and return a string that contains a representation of 
' the XAML structure of content elements in a given TextElement.        
Private Function GetXaml_Renamed(ByVal element As TextElement) As String
    Dim buffer As New StringBuilder()

    ' Position a "navigator" pointer before the opening tag of the element.
    Dim navigator As TextPointer = element.ElementStart

    Do While navigator.CompareTo(element.ElementEnd) < 0
        Select Case navigator.GetPointerContext(LogicalDirection.Forward)
            Case TextPointerContext.ElementStart
                ' Output opening tag of a TextElement
                buffer.AppendFormat("<{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name)
            Case TextPointerContext.ElementEnd
                ' Output closing tag of a TextElement
                buffer.AppendFormat("</{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name)
            Case TextPointerContext.EmbeddedElement
                ' Output simple tag for embedded element
                buffer.AppendFormat("<{0}/>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name)
            Case TextPointerContext.Text
                ' Output the text content of this text run
                buffer.Append(navigator.GetTextInRun(LogicalDirection.Forward))
        End Select

        ' Advance the naviagtor to the next context position.
        navigator = navigator.GetNextContextPosition(LogicalDirection.Forward)

    Loop ' End while.

    Return buffer.ToString()

End Function ' End GetXaml method.

Commenti

Uno dei seguenti è considerato un simbolo:

  • Un tag di apertura o chiusura per un TextElement elemento.

  • Elemento UIElement contenuto in un InlineUIContainer oggetto o BlockUIContainer. Si noti che tale UIElement valore viene sempre conteggiato come un simbolo. Qualsiasi contenuto o elemento aggiuntivo contenuto dall'oggetto UIElement non viene conteggiato come simboli.

  • Carattere Unicode a 16 bit all'interno di un elemento di testo Run .

Se il simbolo successivo viene classificato come EmbeddedElement, ElementStarto ElementEnd (come identificato dal GetPointerContext metodo), il TextPointer metodo restituito da questo metodo è avanzato da un simbolo esattamente dalla posizione corrente.

Se il simbolo successivo viene classificato come Text, il TextPointer restituito da questo metodo è avanzato incollando il testo al simbolo non di testo successivo, ovvero la posizione successiva in cui TextPointerContext non Textè . Il conteggio esatto dei simboli incrociati può essere calcolato in anticipo chiamando il GetTextRunLength metodo .

Si applica a