Obtener propiedades del elemento de la UI Automation

Nota

Esta documentación está dirigida a los desarrolladores de .NET Framework que quieran usar las clases de automatización de la interfaz de usuario administradas definidas en el espacio de nombres System.Windows.Automation. Para ver la información más reciente acerca de la automatización de la interfaz de usuario, consulte Windows Automation API: automatización de la interfaz de usuario.

En este tema se muestra cómo recuperar propiedades de un elemento de automatización de la interfaz de usuario.

Obtenga valor actual de la propiedad

  1. Obtenga la propiedad AutomationElement que desea obtener.

  2. Llame a GetCurrentPropertyValue o recupere la estructura de propiedades Current y obtenga el valor de uno de sus miembros.

Obtener un valor de propiedad almacenado en caché

  1. Obtenga la propiedad AutomationElement que desea obtener. La propiedad debe haberse especificado en CacheRequest.

  2. Llame a GetCachedPropertyValueo recupere la estructura de propiedades Cached y obtenga el valor de uno de sus miembros.

Ejemplo

En el ejemplo siguiente se muestran varias maneras de recuperar las propiedades actuales de 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

Consulte también