CacheRequest.AutomationElementMode CacheRequest.AutomationElementMode CacheRequest.AutomationElementMode CacheRequest.AutomationElementMode Property

정의

반환된 요소에 내부 UI(사용자 인터페이스)user interface (UI)에 대한 전체 참조가 포함될지 아니면 캐시된 정보만 포함될지를 지정하는 값을 가져오거나 설정합니다.Gets or sets a value that specifies whether returned elements should contain full references to the underlying UI(사용자 인터페이스)user interface (UI), or only cached information.

public:
 property System::Windows::Automation::AutomationElementMode AutomationElementMode { System::Windows::Automation::AutomationElementMode get(); void set(System::Windows::Automation::AutomationElementMode value); };
public System.Windows.Automation.AutomationElementMode AutomationElementMode { get; set; }
member this.AutomationElementMode : System.Windows.Automation.AutomationElementMode with get, set
Public Property AutomationElementMode As AutomationElementMode

속성 값

반환된 요소에 내부 UI(사용자 인터페이스)user interface (UI)에 대한 전체 참조가 포함되면 Full이고, 그렇지 않으면 None입니다.Full if the returned elements have a full reference to the underlying UI(사용자 인터페이스)user interface (UI); otherwise None.

예제

다음 예에서 AutomationElementMode 로 설정 된 None, 결과 캐시 된 속성 및 패턴 검색된 된 개체에 대해 사용할 수 있습니다.In the following example, AutomationElementMode is set to None, with the result that only cached properties and patterns are available for the retrieved object.

/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Push.
/// </summary>
/// <param name="autoElement">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be 
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByPush(AutomationElement elementList)
{
    // Set up the request.
    CacheRequest cacheRequest = new CacheRequest();

    // Do not get a full reference to the cached objects, only to their cached properties and patterns.
    cacheRequest.AutomationElementMode = AutomationElementMode.None;

    // Cache all elements, regardless of whether they are control or content elements.
    cacheRequest.TreeFilter = Automation.RawViewCondition;

    // Property and pattern to cache.
    cacheRequest.Add(AutomationElement.NameProperty);
    cacheRequest.Add(SelectionItemPattern.Pattern);

    // Activate the request.
    cacheRequest.Push();

    // Obtain an element and cache the requested items.
    Condition cond = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);
    AutomationElement elementListItem = elementList.FindFirst(TreeScope.Children, cond);

    // At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
    // While that method was retrieving automation elements, the CacheRequest set in this method 
    // would not be active. 

    // Deactivate the request.
    cacheRequest.Pop();

    // Retrieve the cached property and pattern.
    String itemName = elementListItem.Cached.Name;
    SelectionItemPattern pattern = elementListItem.GetCachedPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;

    // The following is an alternative way of retrieving the Name property.
    itemName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty) as String;

    // This is yet another way, which returns AutomationElement.NotSupported if the element does
    // not supply a value. If the second parameter is false, a default name is returned.
    object objName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, true);
    if (objName == AutomationElement.NotSupported)
    {
        itemName = "Unknown";
    }
    else
    {
        itemName = objName as String;
    }

    // The following call raises an exception, because only the cached properties are available, 
    //  as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
    //  default value (Full), this call would be valid.
    /*** bool enabled = elementListItem.Current.IsEnabled; ***/
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Push.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be 
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByPush(ByVal elementList As AutomationElement)
    ' Set up the request.
    Dim cacheRequest As New CacheRequest()

    ' Do not get a full reference to the cached objects, only to their cached properties and patterns.
    cacheRequest.AutomationElementMode = AutomationElementMode.None

    ' Cache all elements, regardless of whether they are control or content elements.
    cacheRequest.TreeFilter = Automation.RawViewCondition

    ' Property and pattern to cache.
    cacheRequest.Add(AutomationElement.NameProperty)
    cacheRequest.Add(SelectionItemPattern.Pattern)

    ' Activate the request.
    cacheRequest.Push()

    ' Obtain an element and cache the requested items.
    Dim myCondition As New PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, _
        True)
    Dim elementListItem As AutomationElement = elementList.FindFirst(TreeScope.Children, myCondition)

    ' At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
    ' While that method was retrieving automation elements, the CacheRequest set in this method 
    ' would not be active. 
    ' Deactivate the request.
    cacheRequest.Pop()

    ' Retrieve the cached property and pattern.
    Dim itemName As String = elementListItem.Cached.Name
    Dim pattern As SelectionItemPattern = _
        DirectCast(elementListItem.GetCachedPattern(SelectionItemPattern.Pattern), SelectionItemPattern)

    ' The following is an alternative way of retrieving the Name property.
    itemName = CStr(elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty))

    ' This is yet another way, which returns AutomationElement.NotSupported if the element does
    ' not supply a value. If the second parameter is false, a default name is returned.
    Dim objName As Object = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, True)
    If objName Is AutomationElement.NotSupported Then
        itemName = "Unknown"
    Else
        itemName = CStr(objName)
    End If
    ' The following call raises an exception, because only the cached properties are available, 
    '  as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
    '  default value (Full), this call would be valid.
    '** bool enabled = elementListItem.Current.IsEnabled; **

End Sub 'CachePropertiesByPush

설명

Full 기본 값 이며, 반환 되는 요소 내부에 대 한 전체 참조를 포함 하도록 지정 UIUI합니다.Full is the default value, and specifies that returned elements contain a full reference to the underlying UIUI. None 반환 되는 요소는 기본 참조가 없는 지정 UIUI, 캐시 된 정보만 포함 합니다.None specifies that the returned elements have no reference to the underlying UIUI, and contain only cached information.

포함 하 여 요소에 대해 특정 작업 GetCurrentPropertyValue, GetCurrentPattern, 및 SetFocus, 전체 참조를 필요로;에서이 수행 하는 none이 있는 요소에서 결과 InvalidOperationException입니다.Certain operations on elements, including GetCurrentPropertyValue, GetCurrentPattern, and SetFocus, require a full reference; attempting to perform these on an element that has none results in an InvalidOperationException.

사용 하 여 None 오버 헤드를 방지 하므로 속성만 필요할 경우 더 효율적일 수 있습니다 전체 참조를 설정 합니다.Using None can be more efficient when only properties are needed, as it avoids the overhead involved in setting up full references.

적용 대상

추가 정보