Eigenschappen van UI Automation-element ophalen

Opmerking

Deze documentatie is bedoeld voor .NET Framework-ontwikkelaars die de beheerde UI Automation-klassen willen gebruiken die zijn gedefinieerd in de System.Windows.Automation naamruimte. Zie Windows Automation-API: UI Automation voor de meest recente informatie over UI Automation.

In dit onderwerp wordt beschreven hoe u eigenschappen van een UI Automation-element ophaalt.

De huidige eigenschapswaarde ophalen

  1. Verkrijg de AutomationElement waarvan u de eigenschap wilt opvragen.

  2. Roep GetCurrentPropertyValue aan, of haal de Current-eigenschapsstructuur op en krijg de waarde van een van de leden.

Een eigenschapswaarde in cache ophalen

  1. Verkrijg de AutomationElement waarvan u de eigenschap wilt opvragen. De eigenschap moet zijn opgegeven in de CacheRequest.

  2. Roep GetCachedPropertyValuede Cached eigenschapsstructuur aan of haal de waarde op van een van de leden.

Voorbeeld

In het volgende voorbeeld ziet u verschillende manieren om de actuele eigenschappen van een AutomationElement te ophalen.

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

Zie ook