TextPointer.GetNextContextPosition(LogicalDirection) TextPointer.GetNextContextPosition(LogicalDirection) TextPointer.GetNextContextPosition(LogicalDirection) TextPointer.GetNextContextPosition(LogicalDirection) Method

Definición

Devuelve un puntero al símbolo siguiente en la dirección lógica especificada.Returns a pointer to the next symbol in the specified logical direction.

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

Parámetros

direction
LogicalDirection LogicalDirection LogicalDirection LogicalDirection

Uno de los valores de LogicalDirection que especifica la dirección lógica en la que buscar el símbolo siguiente.One of the LogicalDirection values that specifies the logical direction in which to search for the next symbol.

Devoluciones

TextPointer al símbolo siguiente en la dirección solicitada o null si el TextPointer actual limita el inicio o el fin del contenido.A TextPointer to the next symbol in the requested direction, or null if the current TextPointer borders the start or end of content.

Ejemplos

El ejemplo siguiente muestra un uso de este método.The following example demonstrates a use for this method. El ejemplo se usa el GetNextContextPosition método junto con el GetPointerContext método para recorrer y extraer los símbolos en un determinado TextElement.The example uses the GetNextContextPosition method in conjunction with the GetPointerContext method to traverse and extract the symbols in a specified TextElement.

Aunque el ejemplo se puede usar para extraer un XAMLXAML estructura para el contenido de un determinado TextElement, que está pensado únicamente con fines ilustrativos y no debe usarse en código de producción.While the example can be used to extract a XAMLXAML structure for the contents of a given TextElement, it is intended for illustrative purposes only, and should not be used in production code. Consulte la System.Xml espacio de nombres para un amplio conjunto de tipos diseñados para trabajar con y procesamiento de XML.See the System.Xml namespace for a rich set of types designed for working with and processing 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.

Comentarios

Cualquiera de las siguientes acciones se considera un símbolo:Any of the following is considered to be a symbol:

Si el símbolo siguiente se clasifica por categorías como EmbeddedElement, ElementStart, o ElementEnd (identificada por el GetPointerContext método), el TextPointer devuelta por este método avanza por exactamente un símbolo desde la posición actual.If the next symbol is categorized as EmbeddedElement, ElementStart, or ElementEnd (as identified by the GetPointerContext method), then the TextPointer returned by this method is advanced by exactly one symbol from the current position.

Si el símbolo siguiente se clasifica por categorías como Text, el TextPointer devuelto por este método avanza más allá del texto en el símbolo de no texto siguiente (es decir, la siguiente posición donde la TextPointerContext no Text).If the next symbol is categorized as Text, then the TextPointer returned by this method is advanced past the text to the next non-text symbol (that is, the next position where the TextPointerContext is not Text). El recuento exacto de símbolos cruzado se puede calcular de antemano mediante una llamada a la GetTextRunLength método.The exact symbol count crossed can be calculated in advance by calling the GetTextRunLength method.

Se aplica a