TextPointer.GetPointerContext(LogicalDirection) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a category indicator for the content adjacent to the current TextPointer in the specified logical direction.
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
Parameters
- direction
- LogicalDirection
One of the LogicalDirection values that specifies the logical direction in which to determine the category for adjacent content.
Returns
One of the TextPointerContext values that indicates the category for adjacent content in the specified logical direction.
Examples
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
' 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
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈