Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextPointer.GetPointerContext Method (LogicalDirection)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns a category indicator for the content adjacent to the current TextPointer in the specified logical direction.

Namespace:   System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)

public TextPointerContext GetPointerContext(
	LogicalDirection direction
)

Parameters

direction
Type: System.Windows.Documents.LogicalDirection

One of the LogicalDirection values that specifies the logical direction in which to determine the category for adjacent content.

Return Value

Type: System.Windows.Documents.TextPointerContext

One of the TextPointerContext values that indicates the category for adjacent content in the specified logical direction.

The following example demonstrates a use for this method. The example uses the GetPointerContext method to implement an algorithm for calculating the balance of opening and closing element tags between two specified TextPointer positions. Each opening element tag is counted as +1, and each closing element tag is counted as –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

.NET Framework
Available since 3.0
Return to top
Show:
© 2018 Microsoft