CacheRequest.TreeScope Propriété

Définition

Obtient ou définit une valeur qui spécifie si la mise en cache s'effectue uniquement pour la racine du sous-arbre ou également pour ses enfants ou descendants.

C#
public System.Windows.Automation.TreeScope TreeScope { get; set; }

Valeur de propriété

TreeScope

Une ou plusieurs des valeurs Element, Children, Descendants ou Subtree. La valeur par défaut est Element.

Exceptions

Une tentative a été faite d'affecter Parent ou Ancestors à la propriété.

Exemples

Dans l’exemple suivant, un élément de zone de liste est obtenu à partir de l’élément de fenêtre parent alors qu’un CacheRequest élément est actif et TreeScope est Children. Les propriétés spécifiées des éléments enfants (autrement dit, les éléments de liste) sont stockées dans le cache et peuvent être récupérées à partir de la CachedChildren zone de liste.

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

L’étendue de la mise en cache est liée à l’objet ou aux objets extraits, et non à l’objet sur lequel FindFirst ou FindAll est appelé. Consultez l'exemple.

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