TextPointer.GetNextContextPosition(LogicalDirection) メソッド

定義

指定された論理方向の次のシンボルへのポインターを返します。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

パラメーター

direction
LogicalDirection

次のシンボルを検索する論理方向を指定する LogicalDirection 値のいずれか。One of the LogicalDirection values that specifies the logical direction in which to search for the next symbol.

戻り値

指定した方向の次のシンボルへの TextPointer。現在の TextPointer がコンテンツの先頭または末尾に隣接している場合は nullA TextPointer to the next symbol in the requested direction, or null if the current TextPointer borders the start or end of content.

このメソッドの使用例を次に示します。The following example demonstrates a use for this method. この例ではGetNextContextPosition 、メソッドをGetPointerContextメソッドと組み合わせて使用して、指定したTextElementのシンボルを走査し、抽出します。The example uses the GetNextContextPosition method in conjunction with the GetPointerContext method to traverse and extract the symbols in a specified TextElement.

この例は、指定XAMLXAML TextElementされたの内容の構造を抽出するために使用できますが、説明的な目的だけを目的としています。運用環境のコードでは使用しないでください。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. XML の操作と処理用に設計された豊富な型の名前空間については、「」を参照してください。System.XmlSee 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.

注釈

次のいずれかがシンボルであると見なされます。Any of the following is considered to be a symbol:

  • TextElement要素の開始タグまたは終了タグ。An opening or closing tag for a TextElement element.

  • またはInlineUIContainer UIElement に格納されBlockUIContainerている要素。A UIElement element contained in an InlineUIContainer or BlockUIContainer. このようUIElementなは常に1つの記号としてカウントされることに注意しUIElementてください。に含まれる追加のコンテンツまたは要素は、シンボルとしてカウントされません。Note that such a UIElement is always counted as exactly one symbol; any additional content or elements contained by the UIElement are not counted as symbols.

  • UnicodeUnicode テキストRun要素内の16ビット文字。A 16-bit UnicodeUnicode character inside of a text Run element.

次のシンボルがEmbeddedElementGetPointerContextメソッドによっElementStartて識別ElementEndされる、、またはとして分類TextPointerされている場合、このメソッドによって返されるは、現在の位置からの1つのシンボルによって高度になります。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.

次のシンボルがとしてText分類されTextPointerている場合、このメソッドによって返されるは、テキストの次の非テキストシンボル (つまり、 TextPointerContextがでない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). 正確なシンボルカウントを超えた場合は、メソッドをGetTextRunLength呼び出すことによって事前に計算できます。The exact symbol count crossed can be calculated in advance by calling the GetTextRunLength method.

適用対象