TextPatternRange.FindAttribute Méthode

Définition

Retourne un sous-ensemble de la plage de texte qui a la valeur d'attribut spécifiée.

C#
public System.Windows.Automation.Text.TextPatternRange FindAttribute(System.Windows.Automation.AutomationTextAttribute attribute, object value, bool backward);

Paramètres

attribute
AutomationTextAttribute

Attribut à rechercher.

value
Object

Valeur d'attribut à rechercher. Cette valeur doit correspondre au type spécifié pour l'attribut.

backward
Boolean

true si la dernière plage de texte doit être retournée à la place de la première ; sinon, false.

Retours

Plage de texte dont l’attribut et la valeur d’attribut correspondent ; sinon, null (Nothing en Visual Basic).

Exemples

C#
 private TextPatternRange RangeFromAttribute(AutomationElement target)
{
    // Specify the control type we're looking for, in this case 'Document'
    PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

    // target --> The root AutomationElement.
    AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);

    TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

    if (textpatternPattern == null)
    {
        Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
        return null;
    }
    TextPatternRange[] currentSelelction = textpatternPattern.GetSelection();
    // Find 'italic' range
    return currentSelelction[0].FindAttribute(TextPattern.IsItalicAttribute, true, false);
}

Remarques

Il n’y a pas de différenciation entre le texte masqué et le texte visible. Les clients UI Automation peuvent utiliser IsHiddenAttribute pour case activée la visibilité du texte.

Remarque

Utilisez DocumentRange pour rechercher l’intégralité du document.

S’applique à

Produit Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Voir aussi