Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

AutomationElement.Cached Property

Gets the cached UI Automation property values for this AutomationElement object.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)
public AutomationElement..::.AutomationElementInformation Cached { get; }

Property Value

Type: System.Windows.Automation.AutomationElement.AutomationElementInformation
A structure containing the cached property values for the AutomationElement.
ExceptionCondition
InvalidOperationException

There are no cached properties.

ElementNotAvailableException

The UI for the AutomationElement no longer exists.

The accessors for UI Automation properties are represented as properties of the structure returned by Cached. You do not need to retrieve the structure; you can access its members directly, as in the example below. For specific information on the properties available and their use, see AutomationElement.AutomationElementInformation.

To get the current value of UI Automation properties on this element use the Current property.

The following example shows how the Name property can be cached and then retrieved by using the Cached property.

/// <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);
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.