AutomationElement.GetUpdatedCache(CacheRequest) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
캐시가 업데이트된 새 AutomationElement를 검색합니다.
public:
System::Windows::Automation::AutomationElement ^ GetUpdatedCache(System::Windows::Automation::CacheRequest ^ request);
public System.Windows.Automation.AutomationElement GetUpdatedCache (System.Windows.Automation.CacheRequest request);
member this.GetUpdatedCache : System.Windows.Automation.CacheRequest -> System.Windows.Automation.AutomationElement
Public Function GetUpdatedCache (request As CacheRequest) As AutomationElement
매개 변수
- request
- CacheRequest
업데이트된 캐시에 포함될 패턴 및 속성입니다.
반환
캐시가 업데이트된 새 AutomationElement입니다.
예제
다음 예제에서는 콤보 상자의 선택이 변경 될 때마다 캐시 업데이트 될 수 있습니다 하는 방법을 보여 줍니다.
CacheRequest comboCacheRequest;
AutomationEventHandler selectHandler;
AutomationElement elementCombo;
AutomationElement selectedItem;
/// <summary>
/// Retrieves a combo box automation element, caches a pattern and a property,
/// and registers the event handler.
/// </summary>
/// <param name="elementAppWindow">The element for the parent window.</param>
private void SetupComboElement(AutomationElement elementAppWindow)
{
// Set up the CacheRequest.
comboCacheRequest = new CacheRequest();
comboCacheRequest.Add(SelectionPattern.Pattern);
comboCacheRequest.Add(SelectionPattern.SelectionProperty);
comboCacheRequest.Add(AutomationElement.NameProperty);
comboCacheRequest.TreeScope = TreeScope.Element | TreeScope.Descendants;
// Activate the CacheRequest and get the element.
using (comboCacheRequest.Activate())
{
// Load the combo box element and cache the specified properties and patterns.
Condition propCondition = new PropertyCondition(
AutomationElement.AutomationIdProperty, "comboBox1", PropertyConditionFlags.IgnoreCase);
elementCombo = elementAppWindow.FindFirst(TreeScope.Descendants, propCondition);
}
// Get the list from the combo box.
Condition propCondition1 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List);
AutomationElement listElement = elementCombo.FindFirst(TreeScope.Children, propCondition1);
// Register for ElementSelectedEvent on list items.
if (listElement != null)
{
Automation.AddAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, listElement,
TreeScope.Children, selectHandler = new AutomationEventHandler(OnListItemSelect));
}
}
/// <summary>
/// Handle ElementSelectedEvent on items in the combo box.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnListItemSelect(object src, AutomationEventArgs e)
{
// Update the cache.
AutomationElement updatedElement = elementCombo.GetUpdatedCache(comboCacheRequest);
// Retrieve the pattern and the selected item from the cache. This code is here only to
// demonstrate that the current selection can now be retrieved from the cache. In an application,
// this would be done only when the information was needed.
SelectionPattern pattern = updatedElement.GetCachedPattern(SelectionPattern.Pattern) as SelectionPattern;
AutomationElement[] selectedItems = pattern.Cached.GetSelection();
selectedItem = selectedItems[0];
}
Private comboCacheRequest As CacheRequest
Private selectHandler As AutomationEventHandler
Private elementCombo As AutomationElement
Private selectedItem As AutomationElement
''' <summary>
''' Retrieves a combo box automation element, caches a pattern and a property,
''' and registers the event handler.
''' </summary>
''' <param name="elementAppWindow">The element for the parent window.</param>
Private Sub SetupComboElement(ByVal elementAppWindow As AutomationElement)
' Set up the CacheRequest.
comboCacheRequest = New CacheRequest()
comboCacheRequest.Add(SelectionPattern.Pattern)
comboCacheRequest.Add(SelectionPattern.SelectionProperty)
comboCacheRequest.Add(AutomationElement.NameProperty)
comboCacheRequest.TreeScope = TreeScope.Element Or TreeScope.Descendants
' Activate the CacheRequest and get the element.
Using comboCacheRequest.Activate()
' Load the combo box element and cache the specified properties and patterns.
Dim propCondition As New PropertyCondition(AutomationElement.AutomationIdProperty, "comboBox1", PropertyConditionFlags.IgnoreCase)
elementCombo = elementAppWindow.FindFirst(TreeScope.Descendants, propCondition)
' Get the list from the combo box.
Dim propCondition1 As New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List)
Dim listElement As AutomationElement = elementCombo.FindFirst(TreeScope.Children, propCondition1)
' Register for ElementSelectedEvent on list items.
selectHandler = New AutomationEventHandler(AddressOf OnListItemSelect)
If (listElement IsNot Nothing) Then
Automation.AddAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, listElement, _
TreeScope.Children, selectHandler)
End If
End Using
End Sub
''' <summary>
''' Handle ElementSelectedEvent on items in the combo box.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnListItemSelect(ByVal src As Object, ByVal e As AutomationEventArgs)
' Update the cache.
Dim updatedElement As AutomationElement = elementCombo.GetUpdatedCache(comboCacheRequest)
' Retrieve the pattern and the selected item from the cache. This code is here only to
' demonstrate that the current selection can now be retrieved from the cache. In an application,
' this would be done only when the information was needed.
Dim pattern As SelectionPattern = _
DirectCast(updatedElement.GetCachedPattern(SelectionPattern.Pattern), SelectionPattern)
Dim selectedItems As AutomationElement() = pattern.Cached.GetSelection()
selectedItem = selectedItems(0)
End Sub
설명
원래 AutomationElement 변경 되지 않습니다. GetUpdatedCache는 동일한 UI(사용자 인터페이스)를 참조하고 가 동일한 RuntimeIdProperty새 AutomationElement를 반환합니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET