AutomationElement.GetCachedPropertyValue メソッド

定義

指定したプロパティのキャッシュされた値を AutomationElementから取得します。

オーバーロード

名前 説明
GetCachedPropertyValue(AutomationProperty)

この AutomationElementのキャッシュから、指定したプロパティの値を取得します。 ターゲット ユーザー インターフェイス (UI) 要素で明示的にサポートされていないプロパティに対して、プロパティ型の適切な既定値が返されます。

GetCachedPropertyValue(AutomationProperty, Boolean)

この AutomationElementのキャッシュから、指定したプロパティの値を取得します。必要に応じて、既定のプロパティは無視します。

注釈

GetCachedPropertyValue は、指定したプロパティを AutomationElementのキャッシュから取得します。 現在のプロパティを取得するには、 GetCurrentPropertyValueを呼び出します。

GetCachedPropertyValue(AutomationProperty)

この AutomationElementのキャッシュから、指定したプロパティの値を取得します。 ターゲット ユーザー インターフェイス (UI) 要素で明示的にサポートされていないプロパティに対して、プロパティ型の適切な既定値が返されます。

public:
 System::Object ^ GetCachedPropertyValue(System::Windows::Automation::AutomationProperty ^ property);
public object GetCachedPropertyValue(System.Windows.Automation.AutomationProperty property);
member this.GetCachedPropertyValue : System.Windows.Automation.AutomationProperty -> obj
Public Function GetCachedPropertyValue (property As AutomationProperty) As Object

パラメーター

property
AutomationProperty

取得するプロパティの識別子。

返品

指定したプロパティの値を格納しているオブジェクト。

例外

要求されたプロパティがキャッシュにありません。

AutomationElementのユーザー インターフェイス (UI) が存在しなくなりました。

このメソッドを使用してキャッシュされたプロパティを取得する方法を次に示します。

/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Push.
/// </summary>
/// <param name="autoElement">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be 
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByPush(AutomationElement elementList)
{
    // Set up the request.
    CacheRequest cacheRequest = new CacheRequest();

    // Do not get a full reference to the cached objects, only to their cached properties and patterns.
    cacheRequest.AutomationElementMode = AutomationElementMode.None;

    // Cache all elements, regardless of whether they are control or content elements.
    cacheRequest.TreeFilter = Automation.RawViewCondition;

    // Property and pattern to cache.
    cacheRequest.Add(AutomationElement.NameProperty);
    cacheRequest.Add(SelectionItemPattern.Pattern);

    // Activate the request.
    cacheRequest.Push();

    // Obtain an element and cache the requested items.
    Condition cond = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);
    AutomationElement elementListItem = elementList.FindFirst(TreeScope.Children, cond);

    // At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
    // While that method was retrieving automation elements, the CacheRequest set in this method 
    // would not be active. 

    // Deactivate the request.
    cacheRequest.Pop();

    // Retrieve the cached property and pattern.
    String itemName = elementListItem.Cached.Name;
    SelectionItemPattern pattern = elementListItem.GetCachedPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;

    // The following is an alternative way of retrieving the Name property.
    itemName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty) as String;

    // This is yet another way, which returns AutomationElement.NotSupported if the element does
    // not supply a value. If the second parameter is false, a default name is returned.
    object objName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, true);
    if (objName == AutomationElement.NotSupported)
    {
        itemName = "Unknown";
    }
    else
    {
        itemName = objName as String;
    }

    // The following call raises an exception, because only the cached properties are available, 
    //  as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
    //  default value (Full), this call would be valid.
    /*** bool enabled = elementListItem.Current.IsEnabled; ***/
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Push.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be 
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByPush(ByVal elementList As AutomationElement)
    ' Set up the request.
    Dim cacheRequest As New CacheRequest()

    ' Do not get a full reference to the cached objects, only to their cached properties and patterns.
    cacheRequest.AutomationElementMode = AutomationElementMode.None

    ' Cache all elements, regardless of whether they are control or content elements.
    cacheRequest.TreeFilter = Automation.RawViewCondition

    ' Property and pattern to cache.
    cacheRequest.Add(AutomationElement.NameProperty)
    cacheRequest.Add(SelectionItemPattern.Pattern)

    ' Activate the request.
    cacheRequest.Push()

    ' Obtain an element and cache the requested items.
    Dim myCondition As New PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, _
        True)
    Dim elementListItem As AutomationElement = elementList.FindFirst(TreeScope.Children, myCondition)

    ' At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
    ' While that method was retrieving automation elements, the CacheRequest set in this method 
    ' would not be active. 
    ' Deactivate the request.
    cacheRequest.Pop()

    ' Retrieve the cached property and pattern.
    Dim itemName As String = elementListItem.Cached.Name
    Dim pattern As SelectionItemPattern = _
        DirectCast(elementListItem.GetCachedPattern(SelectionItemPattern.Pattern), SelectionItemPattern)

    ' The following is an alternative way of retrieving the Name property.
    itemName = CStr(elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty))

    ' This is yet another way, which returns AutomationElement.NotSupported if the element does
    ' not supply a value. If the second parameter is false, a default name is returned.
    Dim objName As Object = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, True)
    If objName Is AutomationElement.NotSupported Then
        itemName = "Unknown"
    Else
        itemName = CStr(objName)
    End If
    ' The following call raises an exception, because only the cached properties are available, 
    '  as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
    '  default value (Full), this call would be valid.
    '** bool enabled = elementListItem.Current.IsEnabled; **

End Sub

注釈

要素自体の UI オートメーション プロバイダーがプロパティをサポートしている場合は、プロパティの値が返されます。 それ以外の場合は、UI オートメーションで指定された既定のプロパティが返されます。 既定のプロパティについては、AutomationElementなど、AcceleratorKeyPropertyのプロパティ識別子フィールドを参照してください。

GetCachedPropertyValue は、指定したプロパティを AutomationElementのキャッシュから取得します。 指定したプロパティ呼び出しの現在のオブジェクトを取得するには、 GetCurrentPropertyValueします。

このメソッドは、要求されたプロパティが以前にキャッシュされていない場合に例外をスローします。

適用対象

GetCachedPropertyValue(AutomationProperty, Boolean)

この AutomationElementのキャッシュから、指定したプロパティの値を取得します。必要に応じて、既定のプロパティは無視します。

public:
 System::Object ^ GetCachedPropertyValue(System::Windows::Automation::AutomationProperty ^ property, bool ignoreDefaultValue);
public object GetCachedPropertyValue(System.Windows.Automation.AutomationProperty property, bool ignoreDefaultValue);
member this.GetCachedPropertyValue : System.Windows.Automation.AutomationProperty * bool -> obj
Public Function GetCachedPropertyValue (property As AutomationProperty, ignoreDefaultValue As Boolean) As Object

パラメーター

property
AutomationProperty

取得するプロパティの識別子。

ignoreDefaultValue
Boolean

指定したプロパティがサポートされていない場合に既定値を無視するかどうかを指定する値。

返品

指定したプロパティの値を含むオブジェクト。要素が値を指定せず、NotSupportedignoreDefaultValue場合にtrue

例外

要求されたプロパティがキャッシュにありません。

AutomationElementの UI が存在しなくなりました。

次の例は、このメソッドを使用してキャッシュされたプロパティを取得する方法を示しています。

/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Push.
/// </summary>
/// <param name="autoElement">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be 
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByPush(AutomationElement elementList)
{
    // Set up the request.
    CacheRequest cacheRequest = new CacheRequest();

    // Do not get a full reference to the cached objects, only to their cached properties and patterns.
    cacheRequest.AutomationElementMode = AutomationElementMode.None;

    // Cache all elements, regardless of whether they are control or content elements.
    cacheRequest.TreeFilter = Automation.RawViewCondition;

    // Property and pattern to cache.
    cacheRequest.Add(AutomationElement.NameProperty);
    cacheRequest.Add(SelectionItemPattern.Pattern);

    // Activate the request.
    cacheRequest.Push();

    // Obtain an element and cache the requested items.
    Condition cond = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);
    AutomationElement elementListItem = elementList.FindFirst(TreeScope.Children, cond);

    // At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
    // While that method was retrieving automation elements, the CacheRequest set in this method 
    // would not be active. 

    // Deactivate the request.
    cacheRequest.Pop();

    // Retrieve the cached property and pattern.
    String itemName = elementListItem.Cached.Name;
    SelectionItemPattern pattern = elementListItem.GetCachedPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;

    // The following is an alternative way of retrieving the Name property.
    itemName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty) as String;

    // This is yet another way, which returns AutomationElement.NotSupported if the element does
    // not supply a value. If the second parameter is false, a default name is returned.
    object objName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, true);
    if (objName == AutomationElement.NotSupported)
    {
        itemName = "Unknown";
    }
    else
    {
        itemName = objName as String;
    }

    // The following call raises an exception, because only the cached properties are available, 
    //  as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
    //  default value (Full), this call would be valid.
    /*** bool enabled = elementListItem.Current.IsEnabled; ***/
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Push.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be 
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByPush(ByVal elementList As AutomationElement)
    ' Set up the request.
    Dim cacheRequest As New CacheRequest()

    ' Do not get a full reference to the cached objects, only to their cached properties and patterns.
    cacheRequest.AutomationElementMode = AutomationElementMode.None

    ' Cache all elements, regardless of whether they are control or content elements.
    cacheRequest.TreeFilter = Automation.RawViewCondition

    ' Property and pattern to cache.
    cacheRequest.Add(AutomationElement.NameProperty)
    cacheRequest.Add(SelectionItemPattern.Pattern)

    ' Activate the request.
    cacheRequest.Push()

    ' Obtain an element and cache the requested items.
    Dim myCondition As New PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, _
        True)
    Dim elementListItem As AutomationElement = elementList.FindFirst(TreeScope.Children, myCondition)

    ' At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
    ' While that method was retrieving automation elements, the CacheRequest set in this method 
    ' would not be active. 
    ' Deactivate the request.
    cacheRequest.Pop()

    ' Retrieve the cached property and pattern.
    Dim itemName As String = elementListItem.Cached.Name
    Dim pattern As SelectionItemPattern = _
        DirectCast(elementListItem.GetCachedPattern(SelectionItemPattern.Pattern), SelectionItemPattern)

    ' The following is an alternative way of retrieving the Name property.
    itemName = CStr(elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty))

    ' This is yet another way, which returns AutomationElement.NotSupported if the element does
    ' not supply a value. If the second parameter is false, a default name is returned.
    Dim objName As Object = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, True)
    If objName Is AutomationElement.NotSupported Then
        itemName = "Unknown"
    Else
        itemName = CStr(objName)
    End If
    ' The following call raises an exception, because only the cached properties are available, 
    '  as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
    '  default value (Full), this call would be valid.
    '** bool enabled = elementListItem.Current.IsEnabled; **

End Sub

注釈

GetCachedPropertyValue は、 AutomationElementのキャッシュから指定されたプロパティを取得します。 現在のプロパティを取得するには、 GetCurrentPropertyValueを呼び出します。

falseignoreDefaultValueを渡すことは、AutomationElement.GetCachedPropertyValue(AutomationProperty)を呼び出すことと同じです。

要素自体の UI オートメーション プロバイダーがプロパティをサポートしている場合は、プロパティの値が返されます。 それ以外の場合、 ignoreDefaultValuefalseされている場合は、UI オートメーションで指定された既定のプロパティが返されます。 既定のプロパティについては、AutomationElementなど、AcceleratorKeyPropertyのプロパティ識別子フィールドを参照してください。

このメソッドは、要求されたプロパティが以前にキャッシュされていない場合に例外をスローします。

適用対象