AutomationElement.Cached 屬性

定義

取得這個 AutomationElement 物件的快取消費者介面自動化屬性值。

public:
 property System::Windows::Automation::AutomationElement::AutomationElementInformation Cached { System::Windows::Automation::AutomationElement::AutomationElementInformation get(); };
public System.Windows.Automation.AutomationElement.AutomationElementInformation Cached { get; }
member this.Cached : System.Windows.Automation.AutomationElement.AutomationElementInformation
Public ReadOnly Property Cached As AutomationElement.AutomationElementInformation

屬性值

AutomationElement.AutomationElementInformation

包含 AutomationElement 之快取屬性值的結構。

例外狀況

沒有快取屬性。

範例

下列範例示範如何使用 Name 屬性來快取和擷 Cached 取屬性。

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

備註

消費者介面自動化屬性的存取子會表示為 所 Cached 傳回結構的屬性。 您不需要擷取 結構;您可以直接存取其成員,如下列範例所示。 如需可用屬性及其使用的特定資訊,請參閱 AutomationElement.AutomationElementInformation

若要取得這個專案上目前消費者介面自動化屬性值, Current 請使用 屬性。

適用於

另請參閱