TextPointer.GetPointerContext(LogicalDirection) メソッド

定義

指定された論理方向で現在の TextPointer に隣接するコンテンツのカテゴリ インジケーターを返します。

public:
 System::Windows::Documents::TextPointerContext GetPointerContext(System::Windows::Documents::LogicalDirection direction);
public System.Windows.Documents.TextPointerContext GetPointerContext (System.Windows.Documents.LogicalDirection direction);
member this.GetPointerContext : System.Windows.Documents.LogicalDirection -> System.Windows.Documents.TextPointerContext
Public Function GetPointerContext (direction As LogicalDirection) As TextPointerContext

パラメーター

direction
LogicalDirection

隣接するコンテンツのカテゴリを決定する論理方向を指定する LogicalDirection 値のいずれか。

戻り値

TextPointerContext

指定された論理方向の隣接するコンテンツのカテゴリを指定する TextPointerContext 値のいずれか。

次の例では、このメソッドの使用方法を示します。 この例では、メソッドを GetPointerContext 使用して、指定した TextPointer 2 つの位置間の開始要素タグと終了要素タグのバランスを計算するためのアルゴリズムを実装します。 各開始要素タグは +1 としてカウントされ、各終了要素タグは -1 としてカウントされます。

// Calculate and return the relative balance of opening and closing element tags
// between two specified TextPointers.
int GetElementTagBalance(TextPointer start, TextPointer end)
{
    int balance = 0;
 
    while (start != null && start.CompareTo(end) < 0)
    {
        TextPointerContext forwardContext = start.GetPointerContext(LogicalDirection.Forward);
 
        if (forwardContext == TextPointerContext.ElementStart)     balance++;
        else if (forwardContext == TextPointerContext.ElementEnd)  balance--;
             
        start = start.GetNextContextPosition(LogicalDirection.Forward);
    } // End while.
 
    return balance;
} // End GetElementTagBalance
' Calculate and return the relative balance of opening and closing element tags
' between two specified TextPointers.
Private Function GetElementTagBalance(ByVal start As TextPointer, ByVal [end] As TextPointer) As Integer
    Dim balance As Integer = 0

    Do While start IsNot Nothing AndAlso start.CompareTo([end]) < 0
        Dim forwardContext As TextPointerContext = start.GetPointerContext(LogicalDirection.Forward)

        If forwardContext = TextPointerContext.ElementStart Then
            balance += 1
        ElseIf forwardContext = TextPointerContext.ElementEnd Then
            balance -= 1
        End If

        start = start.GetNextContextPosition(LogicalDirection.Forward)

    Loop ' End while.

    Return balance

End Function ' End GetElementTagBalance

適用対象