TextPointer.GetPointerContext(LogicalDirection) Metoda

Definice

Vrátí indikátor kategorie pro obsah sousedící s aktuálním TextPointer v zadaném logickém směru.

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

Parametry

direction
LogicalDirection

Jedna z LogicalDirection hodnot, která určuje logický směr, ve kterém se má určit kategorie sousedního obsahu.

Návraty

TextPointerContext

Jedna z TextPointerContext hodnot, která označuje kategorii sousedního obsahu v zadaném logickém směru.

Příklady

Následující příklad ukazuje použití pro tuto metodu. Příklad používá metodu GetPointerContext k implementaci algoritmu pro výpočet rovnováhy mezi levou a pravou značkou elementu mezi dvěma zadanými TextPointer pozicemi. Každá počáteční značka elementu se počítá jako +1 a každá značka koncového prvku se počítá jako -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

Platí pro