AutomationElement.GetCurrentPattern(AutomationPattern) 메서드

정의

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

검색할 패턴의 식별자입니다.

반환

Object

지정된 패턴이 현재 AutomationElement에서 지원되는 경우 해당 패턴 개체입니다.

예외

패턴이 요소에서 지원되지 않는 경우

AutomationElement에 대한 UI가 더 이상 존재하지 않습니다.

예제

다음 예제에서는이 메서드를 사용 하 여 검색 하는 방법을 보여 줍니다는 SelectionItemPattern에 다음 목록 상자에서 항목을 선택 하는 데 사용 됩니다.

/// <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입니다.

설명

GetCurrentPattern 가용성을 기반으로 해당 호출 시 지정 된 패턴을 가져옵니다.

일부 형태의 UI의 경우 이 메서드는 프로세스 간 성능 오버헤드가 발생합니다. 애플리케이션 패턴을 캐시 하 고 사용 하 여 검색 하 여 오버 헤드 집중할 수 GetCachedPattern입니다.

적용 대상

추가 정보