UI オートメーション要素のプロパティの取得

メモメモ

このドキュメントは、System.Windows.Automation 名前空間で定義されているマネージ UI Automation クラスを使用する .NET Framework 開発者を対象としています。UI Automationに関する最新情報については、「Windows Automation API: UI Automation (Windows オートメーション API: UI オートメーション)」を参照してください。

ここでは、UI Automation要素のプロパティを取得する方法について説明します。

現在のプロパティ値の取得

  1. 取得するプロパティを持つ AutomationElement を取得します。

  2. GetCurrentPropertyValue を呼び出すか、または Current プロパティ構造体を取得し、そのメンバーの 1 つから値を取得します。

キャッシュされたプロパティ値の取得

  1. 取得するプロパティを持つ AutomationElement を取得します。 プロパティは、CacheRequest で指定されている必要があります。

  2. GetCachedPropertyValue を呼び出すか、または Cached プロパティ構造体を取得し、そのメンバーの 1 つから値を取得します。

使用例

次の例では、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 オートメーション クライアントにおけるキャッシュ