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 위치 합니다. 각 여는 요소 태그는 +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

적용 대상