AutomationElement.GetCachedPropertyValue Methode

Definition

Ruft den zwischengespeicherten Wert der angegebenen Eigenschaft aus einem AutomationElement ab.Retrieves the cached value of the specified property from an AutomationElement.

Überlädt

GetCachedPropertyValue(AutomationProperty)

Ruft den Wert der angegebenen Eigenschaft aus dem Cache von diesem AutomationElement ab.Retrieves the value of the specified property from the cache of this AutomationElement. Ein geeigneter Standardwert für den Eigenschaftentyp wird für Eigenschaften zurückgegeben, die nicht explizit vom Benutzeroberfläche (User Interface, UI)user interface (UI)-Zielelement unterstützt werden.An appropriate default value for the property type is returned for properties not explicitly supported by the target Benutzeroberfläche (User Interface, UI)user interface (UI) element.

GetCachedPropertyValue(AutomationProperty, Boolean)

Ruft den Wert der angegebenen Eigenschaft aus dem Cache von diesem AutomationElement ab. Dabei werden optional alle Standardeigenschaften ignoriert.Retrieves the value of the specified property from the cache of this AutomationElement, optionally ignoring any default property.

Hinweise

GetCachedPropertyValueRuft die angegebene Eigenschaft aus dem Cache von AutomationElementab.GetCachedPropertyValue retrieves the specified property from the cache of the AutomationElement. Rufen GetCurrentPropertyValueSie zum Abrufen der aktuellen Eigenschaft auf.To retrieve the current property, call GetCurrentPropertyValue.

GetCachedPropertyValue(AutomationProperty)

Ruft den Wert der angegebenen Eigenschaft aus dem Cache von diesem AutomationElement ab.Retrieves the value of the specified property from the cache of this AutomationElement. Ein geeigneter Standardwert für den Eigenschaftentyp wird für Eigenschaften zurückgegeben, die nicht explizit vom Benutzeroberfläche (User Interface, UI)user interface (UI)-Zielelement unterstützt werden.An appropriate default value for the property type is returned for properties not explicitly supported by the target Benutzeroberfläche (User Interface, 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

Parameter

property
AutomationProperty

Der Bezeichner der abzurufenden Eigenschaft.The identifier of the property to retrieve.

Gibt zurück

Ein Objekt, das den Wert der angegebenen Eigenschaft enthältAn object containing the value of the specified property.

Ausnahmen

Die angeforderte Eigenschaft befindet sich nicht im Cache.The requested property is not in the cache.

Die Benutzeroberfläche (User Interface, UI)user interface (UI) für das AutomationElement ist nicht mehr vorhanden.The Benutzeroberfläche (User Interface, UI)user interface (UI) for the AutomationElement no longer exists.

Beispiele

Im folgenden wird gezeigt, wie diese Methode zum Abrufen einer zwischengespeicherten Eigenschaft verwendet werden kann.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

Hinweise

Wenn der Benutzeroberflächenautomatisierungs-Anbieter für das Element selbst die-Eigenschaft unterstützt, wird der Wert der-Eigenschaft zurückgegeben.If the UI Automation provider for the element itself supports the property, the value of the property is returned. Andernfalls wird eine von BenutzeroberflächenautomatisierungUI Automation angegebene Standard Eigenschaft zurückgegeben.Otherwise, a default property specified by BenutzeroberflächenautomatisierungUI Automation is returned. Informationen zu Standardeigenschaften finden Sie unter den Eigenschaftenbezeichnerfeldern AutomationElementvon AcceleratorKeyProperty, z. b..For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

GetCachedPropertyValueRuft die angegebene Eigenschaft aus dem AutomationElementCache des Caches ab.GetCachedPropertyValue retrieves the specified property from the AutomationElement's cache. , Um das aktuelle-Objekt für den angegebenen Eigenschaften GetCurrentPropertyValueaufzurufen.To retrieve the current object for the specified property call GetCurrentPropertyValue.

Diese Methode löst eine Ausnahme aus, wenn die angeforderte Eigenschaft zuvor nicht zwischengespeichert wurde.This method throws an exception if the requested property was not previously cached.

GetCachedPropertyValue(AutomationProperty, Boolean)

Ruft den Wert der angegebenen Eigenschaft aus dem Cache von diesem AutomationElement ab. Dabei werden optional alle Standardeigenschaften ignoriert.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

Parameter

property
AutomationProperty

Der Bezeichner der abzurufenden Eigenschaft.The identifier of the property to retrieve.

ignoreDefaultValue
Boolean

Ein Wert, der angibt, ob ein Standardwert ignoriert werden soll, wenn die angegebene Eigenschaft nicht unterstützt wird.A value that specifies whether a default value should be ignored if the specified property is not supported.

Gibt zurück

Ein Objekt, das den Wert der angegebenen Eigenschaft enthält, oder NotSupported, wenn das Element keinen Wert bereitstellt und ignoreDefaultValue den Wert true aufweist.An object containing the value of the specified property, or NotSupported if the element does not supply a value and ignoreDefaultValue is true.

Ausnahmen

Die angeforderte Eigenschaft befindet sich nicht im Cache.The requested property is not in the cache.

Die Benutzeroberfläche für das AutomationElement ist nicht mehr vorhanden.The UI for the AutomationElement no longer exists.

Beispiele

Im folgenden Beispiel wird gezeigt, wie diese Methode zum Abrufen einer zwischengespeicherten Eigenschaft verwendet werden kann.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

Hinweise

GetCachedPropertyValueRuft die angegebene Eigenschaft aus dem Cache für die AutomationElementab.GetCachedPropertyValue retrieves the specified property from the cache for the AutomationElement. Rufen GetCurrentPropertyValueSie zum Abrufen der aktuellen Eigenschaft auf.To retrieve the current property, call GetCurrentPropertyValue.

Das übergeben false von entspricht dem Aufrufen AutomationElement.GetCachedPropertyValue(AutomationProperty)von. ignoreDefaultValuePassing false in ignoreDefaultValue is equivalent to calling AutomationElement.GetCachedPropertyValue(AutomationProperty).

Wenn der Benutzeroberflächenautomatisierungs-Anbieter für das Element selbst die-Eigenschaft unterstützt, wird der Wert der-Eigenschaft zurückgegeben.If the UI Automation provider for the element itself supports the property, the value of the property is returned. Andernfalls wird eine ignoreDefaultValue von falseangegebene Standard Eigenschaft zurückgegeben, BenutzeroberflächenautomatisierungUI Automation wenn den Wert hat.Otherwise, if ignoreDefaultValue is false, a default property specified by BenutzeroberflächenautomatisierungUI Automation is returned. Informationen zu Standardeigenschaften finden Sie unter den Eigenschaftenbezeichnerfeldern AutomationElementvon AcceleratorKeyProperty, z. b..For information on default properties, see the property identifier fields of AutomationElement, such as AcceleratorKeyProperty.

Diese Methode löst eine Ausnahme aus, wenn die angeforderte Eigenschaft zuvor nicht zwischengespeichert wurde.This method throws an exception if the requested property was not previously cached.

Gilt für: