다음을 통해 공유


UI 자동화 요소 속성 가져오기

참고참고

이 문서는 System.Windows.Automation 네임스페이스에 정의된 관리되는 UI Automation 클래스를 사용하려는 .NET Framework 개발자를 위해 작성되었습니다.UI Automation에 대한 최신 정보는 Windows Automation API: UI Automation을 참조하십시오.

이 항목에서는 UI Automation 요소의 속성을 검색하는 방법을 보여 줍니다.

현재 속성 값 가져오기

  1. 가져올 속성 값의 AutomationElement를 가져옵니다.

  2. GetCurrentPropertyValue를 호출하거나 Current 속성 구조체를 검색하여 해당 멤버 중 하나에서 값을 가져옵니다.

캐시된 속성 값 가져오기

  1. 가져올 속성 값의 AutomationElement를 가져옵니다. 이 속성은 CacheRequest에 지정되어 있어야 합니다.

  2. GetCachedPropertyValue를 호출하거나 Cached 속성 구조체를 검색하여 해당 멤버 중 하나에서 값을 가져옵니다.

예제

다음 예제에서는 AutomationElement의 현재 속성을 검색하는 여러 방법을 보여 줍니다.

Sub PropertyCallsExample(ByVal elementList As AutomationElement)
    ' The following two calls are equivalent.
    Dim name As String = elementList.Current.Name
    name = CStr(elementList.GetCurrentPropertyValue(AutomationElement.NameProperty))

    ' The following shows how to ignore the default property, which 
    '  would probably be an empty string if the property is not supported.
    '  Passing "false" as the second parameter is equivalent to using the overload
    '  that does not have this parameter.
    Dim help As Object = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, True)
    If help Is AutomationElement.NotSupported Then
        help = "No help available"
    End If
    Dim helpText As String = CStr(help)

End Sub 'PropertyCallsExample
void PropertyCallsExample(AutomationElement elementList)
{
    // The following two calls are equivalent.
    string name = elementList.Current.Name;
    name = elementList.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;

    // The following shows how to ignore the default property, which 
    //  would probably be an empty string if the property is not supported.
    //  Passing "false" as the second parameter is equivalent to using the overload
    //  that does not have this parameter.
    object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
    if (help == AutomationElement.NotSupported)
    {
        help = "No help available";
    }
    string helpText = (string)help;
}

참고 항목

작업

UI 자동화의 캐싱 사용

개념

클라이언트의 UI 자동화 속성

UI 자동화 클라이언트의 캐싱