Pobierz właściwości elementu automatyzacji interfejsu użytkownika

Uwaga

Ta dokumentacja jest przeznaczona dla deweloperów programu .NET Framework, którzy chcą używać zarządzanych klas automatyzacja interfejsu użytkownika zdefiniowanych w System.Windows.Automation przestrzeni nazw. Aby uzyskać najnowsze informacje na temat automatyzacja interfejsu użytkownika, zobacz Interfejs API usługi Windows Automation: automatyzacja interfejsu użytkownika.

W tym temacie przedstawiono sposób pobierania właściwości elementu automatyzacja interfejsu użytkownika.

Pobieranie bieżącej wartości właściwości

  1. AutomationElement Uzyskaj właściwość, którą chcesz uzyskać.

  2. Wywołaj GetCurrentPropertyValuemetodę Current , lub pobierz strukturę właściwości i pobierz wartość z jednego z jego elementów członkowskich.

Pobieranie buforowanej wartości właściwości

  1. AutomationElement Uzyskaj właściwość, którą chcesz uzyskać. Właściwość musi być określona w obiekcie CacheRequest.

  2. Wywołaj GetCachedPropertyValuemetodę Cached , lub pobierz strukturę właściwości i pobierz wartość z jednego z jego elementów członkowskich.

Przykład

W poniższym przykładzie przedstawiono różne sposoby pobierania bieżących właściwości obiektu 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

Zobacz też