AutomationElement.CachedParent Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the cached parent of this AutomationElement.

Namespace:   System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public AutomationElement CachedParent { get; }

Property Value

Type: System.Windows.Automation.AutomationElement

The parent element. The return value can be null if the specified element has no parent—for example, if this element is the root node.

Exception Condition

No parent element is cached.


The UI for the AutomationElement no longer exists.

In the following example, the Name properties of a list box and its list items are cached. The list box element is available in the CachedParent property of each list item element.

/// <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.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)

    // 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];

.NET Framework
Available since 3.0
Return to top