UI 자동화 공급자에서 속성 반환

참고 항목

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

이 항목에는 UI 자동화 공급자가 클라이언트 애플리케이션에 요소의 속성을 반환할 수 있는 방법을 보여주는 샘플 코드가 있습니다.

명시적으로 지원되지 않는 모든 속성의 경우 공급자는 null 을 반환해야 합니다(Visual Basic의 경우Nothing ). 이렇게 하면 UI 자동화가 호스트 창 공급자와 같은 다른 소스에서 속성을 가져올 수 있습니다.

예시

/// <summary>
/// Gets provider property values.
/// </summary>
/// <param name="propId">Property identifier.</param>
/// <returns>The value of the property.</returns>
object IRawElementProviderSimple.GetPropertyValue(int propId)
{
    if (propId == AutomationElementIdentifiers.NameProperty.Id)
    {
        return "Custom list control";
    }
    else if (propId == AutomationElementIdentifiers.ControlTypeProperty.Id)
    {
        return ControlType.List.Id;
    }
    else if (propId == AutomationElementIdentifiers.IsContentElementProperty.Id)
    {
        return true;
    }
    else if (propId == AutomationElementIdentifiers.IsControlElementProperty.Id)
    {
        return true;
    }
    else
    {
        return null;
    }
}
''' <summary>
''' Gets provider property values.
''' </summary>
''' <param name="propId">Property identifier.</param>
''' <returns>The value of the property.</returns>
Function GetPropertyValue(ByVal propId As Integer) As Object _
    Implements IRawElementProviderSimple.GetPropertyValue

    If propId = AutomationElementIdentifiers.NameProperty.Id Then
        Return "Custom list control"
    ElseIf propId = AutomationElementIdentifiers.ControlTypeProperty.Id Then
        Return ControlType.List.Id
    ElseIf propId = AutomationElementIdentifiers.IsContentElementProperty.Id Then
        Return True
    ElseIf propId = AutomationElementIdentifiers.IsControlElementProperty.Id Then
        Return True
    Else
        Return Nothing
    End If
End Function 'IRawElementProviderSimple.GetPropertyValue

참고 항목