TextPointer.GetNextContextPosition(LogicalDirection) メソッド

定義

指定した論理方向の次のシンボルへのポインターを返します。

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 値の 1 つ。

返品

要求された方向の次のシンボルへのTextPointer。現在のTextPointerがコンテンツの先頭または末尾に接する場合にnullします。

次の例では、このメソッドの使用方法を示します。 この例では、 GetNextContextPosition メソッドを GetPointerContext メソッドと組み合わせて使用して、指定した TextElement内のシンボルを走査および抽出します。

この例を使用して、特定の TextElementの内容の XAML 構造体を抽出できますが、これは例示のみを目的としており、実稼働コードでは使用しないでください。 XML の操作と処理用に設計された種類の豊富なセットについては、 System.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.

注釈

次のいずれかがシンボルと見なされます。

  • TextElement要素の開始タグまたは終了タグ。

  • InlineUIContainerまたはBlockUIContainerに含まれるUIElement要素。 このような UIElement は常に 1 つのシンボルとしてカウントされます。 UIElement に含まれる追加のコンテンツまたは要素はシンボルとしてカウントされません。

  • テキスト Run 要素内の 16 ビット Unicode 文字。

次のシンボルが EmbeddedElementElementStart、または ElementEnd ( GetPointerContext メソッドによって識別される) として分類されている場合、このメソッドによって返される TextPointer は、現在の位置から 1 つのシンボルによって進まれます。

次の記号が Textとして分類されている場合、このメソッドによって返される TextPointer は、テキストを次の非テキスト記号 (つまり、 TextPointerContextTextされていない次の位置) まで進みます。 交差した正確なシンボル数は、 GetTextRunLength メソッドを呼び出すことによって事前に計算できます。

適用対象