AutomationElement.Cached Propriété

Définition

Obtient les valeurs de propriété UI Automation mises en cache pour cet AutomationElement objet.

C#
public System.Windows.Automation.AutomationElement.AutomationElementInformation Cached { get; }

Valeur de propriété

AutomationElement.AutomationElementInformation

Structure contenant les valeurs de propriété mises en cache pour AutomationElement.

Exceptions

Il n'y a pas de propriétés mises en cache.

L’interface utilisateur pour AutomationElement n’existe plus.

Exemples

L’exemple suivant montre comment la Name propriété peut être mise en cache, puis récupérée à l’aide de la Cached propriété.

C#
/// <summary>
/// Gets a list box element and caches the Name property of its children (the list items).
/// </summary>
/// <param name="elementMain">The UI Automation element for the parent window.</param>
void CachePropertiesWithScope(AutomationElement elementMain)
{
    AutomationElement elementList;

    // Set up the CacheRequest.
    CacheRequest cacheRequest = new CacheRequest();
    cacheRequest.Add(AutomationElement.NameProperty);
    cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children;

    // Activate the CacheRequest and get the element. Note that the scope of the CacheRequest
    // is in relation to the object being retrieved: the list box and its children are 
    // cached, not the main window and its children.
    using (cacheRequest.Activate())
    {
        // Load the list element and cache the specified properties for its descendants.
        Condition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List);
        elementList = elementMain.FindFirst(TreeScope.Children, cond);
    }
    if (elementList == null) return;

    // The following illustrates that the children of the list are in the cache.
    foreach (AutomationElement listItem in elementList.CachedChildren)
    {
        Console.WriteLine(listItem.Cached.Name);
    }

    // The following call raises an exception, because the IsEnabled property was not cached.
    /*** Console.WriteLine(listItem.Cached.IsEnabled); ***/

    // The following illustrates that because the list box itself was cached, it is now
    // available as the CachedParent of each list item.
    AutomationElement child = elementList.CachedChildren[0];
    Console.WriteLine(child.CachedParent.Cached.Name);
}

Remarques

Les accesseurs pour les propriétés UI Automation sont représentés en tant que propriétés de la structure retournée par Cached. Vous n’avez pas besoin de récupérer la structure ; vous pouvez accéder directement à ses membres, comme dans l’exemple ci-dessous. Pour plus d’informations sur les propriétés disponibles et leur utilisation, consultez AutomationElement.AutomationElementInformation.

Pour obtenir la valeur actuelle des propriétés UI Automation sur cet élément, utilisez la Current propriété.

S’applique à

Produit Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Voir aussi