TextPointer.GetPointerContext Method

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

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft