AutomationElement.GetCurrentPattern(AutomationPattern) 메서드

정의

AutomationElement에서 지정된 패턴 개체를 검색합니다.Retrieves the specified pattern object on this AutomationElement.

public:
 System::Object ^ GetCurrentPattern(System::Windows::Automation::AutomationPattern ^ pattern);
public object GetCurrentPattern (System.Windows.Automation.AutomationPattern pattern);
member this.GetCurrentPattern : System.Windows.Automation.AutomationPattern -> obj
Public Function GetCurrentPattern (pattern As AutomationPattern) As Object

매개 변수

pattern
AutomationPattern

검색할 패턴의 식별자입니다.The identifier of the pattern to retrieve.

반환

지정된 패턴이 현재 AutomationElement에서 지원되는 경우 해당 패턴 개체입니다.The pattern object, if the specified pattern is currently supported by the AutomationElement.

예외

패턴이 요소에서 지원되지 않는 경우The pattern is not supported by the element.

AutomationElement에 대한 UI가 더 이상 존재하지 않습니다.The UI for the AutomationElement no longer exists.

예제

다음 예제에서는이 메서드를 사용 하 여 검색 하는 방법을 보여 줍니다는 SelectionItemPattern에 다음 목록 상자에서 항목을 선택 하는 데 사용 됩니다.The following example shows how to use this method to retrieve a SelectionItemPattern, which is then used to select an item in a list box.

/// <summary>
/// Sets the focus to a list and selects a string item in that list.
/// </summary>
/// <param name="listElement">The list element.</param>
/// <param name="itemText">The text to select.</param>
/// <remarks>
/// This deselects any currently selected items. To add the item to the current selection 
/// in a multiselect list, use AddToSelection instead of Select.
/// </remarks>
public void SelectListItem(AutomationElement listElement, String itemText)
{
    if ((listElement == null) || (itemText == ""))
    {
        throw new ArgumentException("Argument cannot be null or empty.");
    }
    listElement.SetFocus();
    Condition cond = new PropertyCondition(
        AutomationElement.NameProperty, itemText, PropertyConditionFlags.IgnoreCase);
    AutomationElement elementItem = listElement.FindFirst(TreeScope.Children, cond);
    if (elementItem != null)
    {
        SelectionItemPattern pattern;
        try
        {
            pattern = elementItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
        }
        catch (InvalidOperationException ex)
        {
            Console.WriteLine(ex.Message);  // Most likely "Pattern not supported."
            return;
        }
        pattern.Select();
    }
}
''' <summary>
''' Sets the focus to a list and selects a string item in that list.
''' </summary>
''' <param name="listElement">The list element.</param>
''' <param name="itemText">The text to select.</param>
''' <remarks>
''' This deselects any currently selected items. To add the item to the current selection 
''' in a multiselect list, use AddToSelection instead of Select.
''' </remarks>
Public Sub SelectListItem(ByVal listElement As AutomationElement, ByVal itemText As String)
    If listElement Is Nothing OrElse itemText = "" Then
        Throw New ArgumentException("Argument cannot be null or empty.")
    End If
    listElement.SetFocus()
    Dim cond As New PropertyCondition(AutomationElement.NameProperty, itemText, PropertyConditionFlags.IgnoreCase)
    Dim elementItem As AutomationElement = listElement.FindFirst(TreeScope.Children, cond)
    If Not (elementItem Is Nothing) Then
        Dim pattern As SelectionItemPattern
        Try
            pattern = DirectCast(elementItem.GetCurrentPattern(SelectionItemPattern.Pattern), _
                SelectionItemPattern)
        Catch ex As InvalidOperationException
            Console.WriteLine(ex.Message) ' Most likely "Pattern not supported."
            Return
        End Try
        pattern.Select()
    End If

End Sub

참고

예제에서와 같은 자주 반복 되는 작업을 효율적으로 패턴을 캐시 하 고 사용 하 여 것 GetCachedPattern입니다.For often-repeated tasks such as the one in the example, it would be more efficient to cache the pattern and use GetCachedPattern.

설명

GetCurrentPattern 가용성을 기반으로 해당 호출 시 지정 된 패턴을 가져옵니다.GetCurrentPattern gets the specified pattern based on its availability at the time of the call.

일부 형태의 UIUI,이 메서드는 크로스 프로세스 성능 오버 헤드가 부과 됩니다.For some forms of UIUI, this method will incur cross-process performance overhead. 애플리케이션 패턴을 캐시 하 고 사용 하 여 검색 하 여 오버 헤드 집중할 수 GetCachedPattern입니다.Applications can concentrate overhead by caching patterns and then retrieving them by using GetCachedPattern.

적용 대상

추가 정보