다음을 통해 공유


AutomationElement.CachedChildren 속성

정의

AutomationElement의 캐시된 하위 요소 1을 가져 옵니다.

public:
 property System::Windows::Automation::AutomationElementCollection ^ CachedChildren { System::Windows::Automation::AutomationElementCollection ^ get(); };
public System.Windows.Automation.AutomationElementCollection CachedChildren { get; }
member this.CachedChildren : System.Windows.Automation.AutomationElementCollection
Public ReadOnly Property CachedChildren As AutomationElementCollection

속성 값

AutomationElementCollection

자식 요소의 컬렉션입니다. 요소에 자식이 없는 경우 이 컬렉션이 비어 있을 수 있습니다.

예외

AutomationElement에 대한 UI가 더 이상 존재하지 않습니다.

이 요소의 자식을 캐시하도록 요청하지 않은 경우

예제

하는 동안 부모 창 요소에서 다음 예제에서는 목록 상자 요소를 가져옵니다을 CacheRequest 활성 및 TreeScopeChildren합니다. 자식 요소 (즉, 목록 항목)의 지정된 된 속성은 캐시에 저장 되며에서 검색할 수 있습니다는 CachedChildren 목록 상자입니다.

/// <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);
}
''' <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.Add(AutomationElement.NameProperty)
    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
            Return
        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
            Console.WriteLine(listItem.Cached.Name)
        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)
        Console.WriteLine(child.CachedParent.Cached.Name)
    End Using
End Sub

설명

반환된 된 컬렉션의 보기에 의해 결정 됩니다는 TreeFilter 의 상태는 CacheRequest 는 활성 상태 였던 경우이 AutomationElement 개체를 가져온 합니다.

경우에 자식 캐시의 범위는 CacheRequest 포함 Subtree, Children, 또는 Descendants합니다.

경우는 CacheRequest 지정는 어린이 들이 수준에서는 캐시할 있지만 자식이 없는이 속성의 값은 0입니다. 그러나이 수준에서 자식을 캐시의 요청 된 속성을 검색 하려고 예외를 발생 시킵니다.

적용 대상

추가 정보