AutomationElement.GetCachedPropertyValue メソッド

定義

指定したプロパティのキャッシュされた値を AutomationElement から取得します。Retrieves the cached value of the specified property from an AutomationElement.

オーバーロード

GetCachedPropertyValue(AutomationProperty)

指定したプロパティの値をこの AutomationElement のキャッシュから取得します。Retrieves the value of the specified property from the cache of this AutomationElement. ターゲットユーザー インターフェイス (UI)user interface (UI) 要素で明示的にサポートされていないプロパティに対しては、そのプロパティ型の適切な既定値が返されます。An appropriate default value for the property type is returned for properties not explicitly supported by the target ユーザー インターフェイス (UI)user interface (UI) element.

GetCachedPropertyValue(AutomationProperty, Boolean)

指定したプロパティの値をこの AutomationElement のキャッシュから取得します。既定のプロパティを無視するように指定することもできます。Retrieves the value of the specified property from the cache of this AutomationElement, optionally ignoring any default property.

注釈

GetCachedPropertyValueのキャッシュから指定されたプロパティをAutomationElement取得します。GetCachedPropertyValue retrieves the specified property from the cache of the AutomationElement. 現在のプロパティを取得するにGetCurrentPropertyValueは、を呼び出します。To retrieve the current property, call GetCurrentPropertyValue.

GetCachedPropertyValue(AutomationProperty)

指定したプロパティの値をこの AutomationElement のキャッシュから取得します。Retrieves the value of the specified property from the cache of this AutomationElement. ターゲットユーザー インターフェイス (UI)user interface (UI) 要素で明示的にサポートされていないプロパティに対しては、そのプロパティ型の適切な既定値が返されます。An appropriate default value for the property type is returned for properties not explicitly supported by the target ユーザー インターフェイス (UI)user interface (UI) element.

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

取得するプロパティの識別子。The identifier of the property to retrieve.

戻り値

指定したプロパティの値が格納されているオブジェクト。An object containing the value of the specified property.

例外

要求されたプロパティがキャッシュ内にありません。The requested property is not in the cache.

AutomationElement 用の ユーザー インターフェイス (UI)user interface (UI) は存在しません。The ユーザー インターフェイス (UI)user interface (UI) for the AutomationElement no longer exists.

次に、このメソッドを使用してキャッシュされたプロパティを取得する方法を示します。The following shows how this method can be used to retrieve a cached property.

/// <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 オートメーションプロバイダーがプロパティをサポートしている場合は、プロパティの値が返されます。If the UI Automation provider for the element itself supports the property, the value of the property is returned. それ以外の場合は、にUI オートメーションUI Automationよって指定された既定のプロパティが返されます。Otherwise, a default property specified by UI オートメーションUI Automation is returned. 既定のプロパティの詳細については、「」 AutomationElementなど、 AcceleratorKeyPropertyのプロパティ識別子のフィールドを参照してください。For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

GetCachedPropertyValue指定されたプロパティをAutomationElementのキャッシュから取得します。GetCachedPropertyValue retrieves the specified property from the AutomationElement's cache. 指定されたプロパティ呼び出しGetCurrentPropertyValueの現在のオブジェクトを取得する場合は。To retrieve the current object for the specified property call GetCurrentPropertyValue.

要求されたプロパティが以前にキャッシュされていなかった場合、このメソッドは例外をスローします。This method throws an exception if the requested property was not previously cached.

GetCachedPropertyValue(AutomationProperty, Boolean)

指定したプロパティの値をこの AutomationElement のキャッシュから取得します。既定のプロパティを無視するように指定することもできます。Retrieves the value of the specified property from the cache of this AutomationElement, optionally ignoring any default property.

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

取得するプロパティの識別子。The identifier of the property to retrieve.

ignoreDefaultValue
Boolean

指定したプロパティがサポートされていない場合に、既定値を無視するかどうかを指定する値。A value that specifies whether a default value should be ignored if the specified property is not supported.

戻り値

指定したプロパティの値を格納するオブジェクト。または、要素が値を提供せず、ignoreDefaultValuetrue である場合は NotSupportedAn object containing the value of the specified property, or NotSupported if the element does not supply a value and ignoreDefaultValue is true.

例外

要求されたプロパティがキャッシュ内にありません。The requested property is not in the cache.

AutomationElement の UI はなくなりました。The UI for the AutomationElement no longer exists.

次の例は、このメソッドを使用してキャッシュされたプロパティを取得する方法を示しています。The following example shows how this method can be used to retrieve a cached property.

/// <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から指定されたプロパティを取得します。GetCachedPropertyValue retrieves the specified property from the cache for the AutomationElement. 現在のプロパティを取得するにGetCurrentPropertyValueは、を呼び出します。To retrieve the current property, call GetCurrentPropertyValue.

を渡すfalseことAutomationElement.GetCachedPropertyValue(AutomationProperty)は、を呼び出すことと同じです。 ignoreDefaultValuePassing false in ignoreDefaultValue is equivalent to calling AutomationElement.GetCachedPropertyValue(AutomationProperty).

要素の UI オートメーションプロバイダーがプロパティをサポートしている場合は、プロパティの値が返されます。If the UI Automation provider for the element itself supports the property, the value of the property is returned. それ以外のignoreDefaultValue場合false、がの場合は、 UI オートメーションUI Automationによって指定された既定のプロパティが返されます。Otherwise, if ignoreDefaultValue is false, a default property specified by UI オートメーションUI Automation is returned. 既定のプロパティの詳細については、「」 AutomationElementなど、 AcceleratorKeyPropertyのプロパティ識別子のフィールドを参照してください。For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

要求されたプロパティが以前にキャッシュされていなかった場合、このメソッドは例外をスローします。This method throws an exception if the requested property was not previously cached.

適用対象