Obtenir les propriétés d'éléments UI Automation

Notes

Cette documentation s’adresse aux développeurs .NET Framework qui souhaitent utiliser les classes UI Automation managées définies dans l’espace de noms System.Windows.Automation. Pour obtenir les dernières informations sur UI Automation, consultez API Windows Automation : UI Automation.

Cette rubrique explique comment récupérer les propriétés d’un élément UI Automation.

Obtenir une valeur de propriété actuelle

  1. Obtenez la AutomationElement dont vous souhaitez obtenir la propriété.

  2. Appelez GetCurrentPropertyValue ou récupérez structure de propriété Current et obtenez la valeur de l’un de ses membres.

Obtenir une valeur de propriété mise en cache

  1. Obtenez la AutomationElement dont vous souhaitez obtenir la propriété. La propriété doit avoir été spécifiée dans la CacheRequest.

  2. Appelez GetCachedPropertyValue ou récupérez structure de propriété Cached et obtenez la valeur de l’un de ses membres.

Exemple

L’exemple suivant montre différentes façons de récupérer les propriétés actuelles d’une AutomationElement.

void PropertyCallsExample(AutomationElement elementList)
{
    // The following two calls are equivalent.
    string name = elementList.Current.Name;
    name = elementList.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;

    // The following shows how to ignore the default property, which
    //  would probably be an empty string if the property is not supported.
    //  Passing "false" as the second parameter is equivalent to using the overload
    //  that does not have this parameter.
    object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
    if (help == AutomationElement.NotSupported)
    {
        help = "No help available";
    }
    string helpText = (string)help;
}
Sub PropertyCallsExample(ByVal elementList As AutomationElement)
    ' The following two calls are equivalent.
    Dim name As String = elementList.Current.Name
    name = CStr(elementList.GetCurrentPropertyValue(AutomationElement.NameProperty))

    ' The following shows how to ignore the default property, which 
    '  would probably be an empty string if the property is not supported.
    '  Passing "false" as the second parameter is equivalent to using the overload
    '  that does not have this parameter.
    Dim help As Object = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, True)
    If help Is AutomationElement.NotSupported Then
        help = "No help available"
    End If
    Dim helpText As String = CStr(help)

End Sub

Voir aussi