TextPointer.GetPointerContext(LogicalDirection) Metod

Definition

Returnerar en kategoriindikator för innehållet intill den aktuella TextPointer i den angivna logiska riktningen.

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

Parametrar

direction
LogicalDirection

Ett av de LogicalDirection värden som anger den logiska riktningen för att fastställa kategorin för intilliggande innehåll.

Returer

Ett av de TextPointerContext värden som anger kategorin för intilliggande innehåll i den angivna logiska riktningen.

Exempel

I följande exempel visas en användning för den här metoden. I exemplet används GetPointerContext metoden för att implementera en algoritm för att beräkna saldot för att öppna och stänga elementtaggar mellan två angivna TextPointer positioner. Varje inledande elementtagg räknas som +1 och varje avslutande elementtagg räknas som -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

Gäller för