UI オートメーション プロバイダーからのプロパティの返却

Note

このドキュメントは、System.Windows.Automation 名前空間で定義されているマネージド UI オートメーション クラスを使用する .NET Framework 開発者を対象としています。 UI オートメーションの最新情報については、Windows Automation 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

関連項目