Delen via


Eigenschappen van UI Automation-element ophalen

Notitie

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.

Een huidige eigenschapswaarde ophalen

  1. Haal de AutomationElement wiens eigendom u wilt krijgen.

  2. Roep GetCurrentPropertyValuede Current eigenschapsstructuur aan of haal de waarde op van een van de leden.

Een eigenschapswaarde in cache ophalen

  1. Haal de AutomationElement wiens eigendom u wilt krijgen. De eigenschap moet zijn opgegeven in de CacheRequest.

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

Opmerking

In het volgende voorbeeld ziet u verschillende manieren om de huidige eigenschappen van een 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

Zie ook