AutomationElement.CachedChildren Proprietà

Definizione

Ottiene gli elementi figlio memorizzati nella cache dell'oggetto AutomationElement.

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

Valore della proprietà

Raccolta di elementi figlio. Questa raccolta può essere vuota se l'elemento non presenta elementi figlio.

Eccezioni

L'interfaccia utente per AutomationElement non esiste più.

Non è stata effettuata alcuna richiesta per memorizzare nella cache gli elementi figlio di questo elemento.

Esempio

Nell'esempio seguente viene ottenuto un elemento casella di riepilogo dall'elemento finestra padre mentre un CacheRequest oggetto è attivo ed TreeScope è Children. Le proprietà specificate degli elementi figlio , ovvero gli elementi dell'elenco CachedChildren , vengono archiviati nella cache e possono essere recuperati dalla casella di riepilogo.

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

Commenti

La visualizzazione dell'insieme restituito è determinata dalla TreeFilter condizione dell'oggetto CacheRequest attivo quando questo AutomationElement oggetto è stato ottenuto.

I figli vengono memorizzati nella cache solo se l'ambito dell'oggetto CacheRequest incluso Subtree, Childreno Descendants.

Se l'elemento CacheRequest figlio specificato deve essere memorizzato nella cache a questo livello, ma non sono presenti elementi figlio, il valore di questa proprietà è 0. Tuttavia, se non è stata effettuata alcuna richiesta per memorizzare nella cache elementi figlio a questo livello, un tentativo di recuperare la proprietà genera un'eccezione.

Si applica a

Vedi anche