AutomationElement.GetCachedPropertyValue AutomationElement.GetCachedPropertyValue AutomationElement.GetCachedPropertyValue AutomationElement.GetCachedPropertyValue Method

Definizione

Recupera il valore memorizzato nella cache della proprietà specificata da un oggetto AutomationElement.Retrieves the cached value of the specified property from an AutomationElement.

Overload

GetCachedPropertyValue(AutomationProperty) GetCachedPropertyValue(AutomationProperty) GetCachedPropertyValue(AutomationProperty) GetCachedPropertyValue(AutomationProperty)

Recupera il valore della proprietà specificata dalla cache di questo oggetto AutomationElement.Retrieves the value of the specified property from the cache of this AutomationElement. Viene restituito un valore predefinito adeguato al tipo di proprietà per le proprietà supportate in modo non esplicito dall'elemento dell'interfaccia utenteuser interface (UI) di destinazione.An appropriate default value for the property type is returned for properties not explicitly supported by the target interfaccia utenteuser interface (UI) element.

GetCachedPropertyValue(AutomationProperty, Boolean) GetCachedPropertyValue(AutomationProperty, Boolean) GetCachedPropertyValue(AutomationProperty, Boolean) GetCachedPropertyValue(AutomationProperty, Boolean)

Recupera il valore della proprietà specificata dalla cache di questo oggetto AutomationElement, ignorando facoltativamente qualsiasi proprietà predefinita.Retrieves the value of the specified property from the cache of this AutomationElement, optionally ignoring any default property.

Commenti

GetCachedPropertyValueRecupera la proprietà specificata dalla cache dell'oggetto AutomationElement.GetCachedPropertyValue retrieves the specified property from the cache of the AutomationElement. Per recuperare la proprietà corrente, chiamare GetCurrentPropertyValue.To retrieve the current property, call GetCurrentPropertyValue.

GetCachedPropertyValue(AutomationProperty) GetCachedPropertyValue(AutomationProperty) GetCachedPropertyValue(AutomationProperty) GetCachedPropertyValue(AutomationProperty)

Recupera il valore della proprietà specificata dalla cache di questo oggetto AutomationElement.Retrieves the value of the specified property from the cache of this AutomationElement. Viene restituito un valore predefinito adeguato al tipo di proprietà per le proprietà supportate in modo non esplicito dall'elemento dell'interfaccia utenteuser interface (UI) di destinazione.An appropriate default value for the property type is returned for properties not explicitly supported by the target interfaccia utenteuser 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

Parametri

property
AutomationProperty AutomationProperty AutomationProperty AutomationProperty

Identificatore della proprietà da recuperare.The identifier of the property to retrieve.

Restituisce

Oggetto contenente il valore della proprietà specificata.An object containing the value of the specified property.

Eccezioni

La proprietà richiesta non è presente nella cache.The requested property is not in the cache.

L'interfaccia utenteuser interface (UI) per AutomationElement non esiste più.The interfaccia utenteuser interface (UI) for the AutomationElement no longer exists.

Esempi

Di seguito viene illustrato il modo in cui questo metodo può essere utilizzato per recuperare una proprietà memorizzata nella cache.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

Commenti

Se il provider di automazione interfaccia utente per l'elemento stesso supporta la proprietà, viene restituito il valore della proprietà.If the UI Automation provider for the element itself supports the property, the value of the property is returned. In caso contrario, viene restituita Automazione interfaccia utenteUI Automation una proprietà predefinita specificata da.Otherwise, a default property specified by Automazione interfaccia utenteUI Automation is returned. Per informazioni sulle proprietà predefinite, vedere i campi dell'identificatore di AutomationElementproprietà di, AcceleratorKeyPropertyad esempio.For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

GetCachedPropertyValueRecupera la proprietà specificata dalla AutomationElementcache di.GetCachedPropertyValue retrieves the specified property from the AutomationElement's cache. Per recuperare l'oggetto corrente per la chiamata GetCurrentPropertyValuedi proprietà specificata.To retrieve the current object for the specified property call GetCurrentPropertyValue.

Questo metodo genera un'eccezione se la proprietà richiesta non è stata precedentemente memorizzata nella cache.This method throws an exception if the requested property was not previously cached.

GetCachedPropertyValue(AutomationProperty, Boolean) GetCachedPropertyValue(AutomationProperty, Boolean) GetCachedPropertyValue(AutomationProperty, Boolean) GetCachedPropertyValue(AutomationProperty, Boolean)

Recupera il valore della proprietà specificata dalla cache di questo oggetto AutomationElement, ignorando facoltativamente qualsiasi proprietà predefinita.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

Parametri

property
AutomationProperty AutomationProperty AutomationProperty AutomationProperty

Identificatore della proprietà da recuperare.The identifier of the property to retrieve.

ignoreDefaultValue
Boolean Boolean Boolean Boolean

Valore che specifica se un valore predefinito deve essere ignorato in caso di mancato supporto della proprietà specificata.A value that specifies whether a default value should be ignored if the specified property is not supported.

Restituisce

Oggetto contenente il valore della proprietà specificata o NotSupported se l'elemento non fornisce un valore e ignoreDefaultValue è true.An object containing the value of the specified property, or NotSupported if the element does not supply a value and ignoreDefaultValue is true.

Eccezioni

La proprietà richiesta non è presente nella cache.The requested property is not in the cache.

Esempi

Nell'esempio seguente viene illustrato il modo in cui questo metodo può essere utilizzato per recuperare una proprietà memorizzata nella cache.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

Commenti

GetCachedPropertyValueRecupera la proprietà specificata dalla cache per l'oggetto AutomationElement.GetCachedPropertyValue retrieves the specified property from the cache for the AutomationElement. Per recuperare la proprietà corrente, chiamare GetCurrentPropertyValue.To retrieve the current property, call GetCurrentPropertyValue.

Il passaggio falseèequivalente alla chiamata AutomationElement.GetCachedPropertyValue(AutomationProperty)a. ignoreDefaultValuePassing false in ignoreDefaultValue is equivalent to calling AutomationElement.GetCachedPropertyValue(AutomationProperty).

Se il provider di automazione interfaccia utente per l'elemento stesso supporta la proprietà, viene restituito il valore della proprietà.If the UI Automation provider for the element itself supports the property, the value of the property is returned. In caso contrario ignoreDefaultValue , falsese è, viene restituita Automazione interfaccia utenteUI Automation una proprietà predefinita specificata da.Otherwise, if ignoreDefaultValue is false, a default property specified by Automazione interfaccia utenteUI Automation is returned. Per informazioni sulle proprietà predefinite, vedere i campi dell'identificatore di AutomationElementproprietà di, AcceleratorKeyPropertyad esempio.For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

Questo metodo genera un'eccezione se la proprietà richiesta non è stata precedentemente memorizzata nella cache.This method throws an exception if the requested property was not previously cached.

Si applica a