Export (0) Print
Expand All

AutomationElement.CachedParent Property

Gets the cached parent of this AutomationElement.

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

Public ReadOnly Property CachedParent As AutomationElement

Property Value

Type: System.Windows.Automation.AutomationElement
The parent element. The return value can be Nothing if the specified element has no parent—for example, if this element is the root node.


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> 
Sub CachePropertiesWithScope(ByVal elementMain As AutomationElement)
    Dim elementList As AutomationElement

    ' Set up the CacheRequest. 
    Dim cacheRequest As New CacheRequest()
    cacheRequest.TreeScope = TreeScope.Element Or 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. 
        Dim myCondition As New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List)
        elementList = elementMain.FindFirst(TreeScope.Children, myCondition)

        If elementList Is Nothing Then 
        End If 

        ' The following illustrates that the children of the list are in the cache. 
        Dim listItem As AutomationElement
        For Each listItem In elementList.CachedChildren
        Next listItem

        ' 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. 
        Dim child As AutomationElement = elementList.CachedChildren(0)
    End Using 
End Sub 'CachePropertiesWithScope

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft