Export (0) Print
Expand All

TextPointer.GetPointerContext Method

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

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

public TextPointerContext GetPointerContext (
	LogicalDirection direction
)
public TextPointerContext GetPointerContext (
	LogicalDirection direction
)
public function GetPointerContext (
	direction : LogicalDirection
) : TextPointerContext
You cannot use methods in XAML.

Parameters

direction

A logical direction in which to determine the category for adjacent content.

Return Value

A member of the TextPointerContext enumeration that specifies 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, while 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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft