TextPointer.GetPointerContext(LogicalDirection) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne un indicateur de catégorie pour le contenu adjacent au TextPointer actuel dans la direction logique spécifiée.
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
Paramètres
- direction
- LogicalDirection
Une des LogicalDirection valeurs qui spécifie la direction logique dans laquelle déterminer la catégorie pour le contenu adjacent.
Retours
Une des TextPointerContext valeurs qui indique la catégorie pour le contenu adjacent dans la direction logique spécifiée.
Exemples
L’exemple suivant illustre une utilisation pour cette méthode. L’exemple utilise la GetPointerContext méthode pour implémenter un algorithme pour calculer l’équilibre des balises d’élément d’ouverture et de fermeture entre deux positions spécifiées TextPointer . Chaque balise d’élément ouvrant est comptée comme +1, et chaque balise d’élément fermante est comptabilisée comme -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