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

참고 항목

이 설명서는 System.Windows.Automation 네임스페이스에 정의된 관리되는 UI 자동화 클래스를 사용하려는 .NET Framework 개발자를 위한 것입니다. UI 자동화에 대한 최신 정보는 Windows 자동화 API: UI 자동화를 참조하세요.

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

현재 속성 값 가져오기

  1. 속성을 가져오려는 AutomationElement를 가져옵니다.

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

캐시된 속성 값 가져오기

  1. 속성을 가져오려는 AutomationElement를 가져옵니다. 속성은 CacheRequest에 지정되어 있어야 합니다.

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

예시

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

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;
}
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

참고 항목