AutomationElement.GetCurrentPropertyValue 方法

定義

AutomationElement 擷取所指定屬性的目前值。Retrieves the current value of the specified property from an AutomationElement.

多載

GetCurrentPropertyValue(AutomationProperty)

在此 AutomationElement 上擷取所指定屬性的值。Retrieves the value of the specified property on 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.

GetCurrentPropertyValue(AutomationProperty, Boolean)

在此 AutomationElement 上擷取所指定屬性的值,選擇性忽略任何預設屬性。Retrieves the value of the specified property on this AutomationElement, optionally ignoring any default property.

備註

GetCurrentPropertyValue方法所傳回的值在呼叫時是最新的。The value returned by the GetCurrentPropertyValue method is current at the time it is called. 此值隨後會由與互動的使用者介面 (UI)user interface (UI)其他應用程式變更。The value can subsequently change by other applications interacting with the 使用者介面 (UI)user interface (UI).

針對某些形式的UIUI,這個方法會產生跨進程的效能負擔。For some forms of UIUI, this method will incur cross-process performance overhead. 應用程式可以藉由快取屬性,然後使用GetCachedPropertyValue來抓取它們,來專注額外負荷。Applications can concentrate overhead by caching properties and then retrieving them by using GetCachedPropertyValue.

GetCurrentPropertyValue(AutomationProperty)

在此 AutomationElement 上擷取所指定屬性的值。Retrieves the value of the specified property on 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 ^ GetCurrentPropertyValue(System::Windows::Automation::AutomationProperty ^ property);
public object GetCurrentPropertyValue (System.Windows.Automation.AutomationProperty property);
member this.GetCurrentPropertyValue : System.Windows.Automation.AutomationProperty -> obj
Public Function GetCurrentPropertyValue (property As AutomationProperty) As Object

參數

property
AutomationProperty

指定要擷取之屬性的 UI 自動化UI Automation 屬性識別碼。The UI 自動化UI Automation property identifier specifying which property to retrieve.

傳回

包含所指定屬性之值的物件。An object containing the value of the specified property.

例外狀況

AutomationElement 的 UI 不再存在。The UI for the AutomationElement no longer exists.

範例

下列範例會抓取HelpText屬性的目前值。The following example retrieves the current value of the HelpText property. 如果專案未提供預設值,則會傳回預設值。The default value is returned if the element does not provide one.

// elementList is an AutomationElement.
string helpString =
    elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty) as string;
' elementList is an AutomationElement.
Dim helpString As String = _
    CStr(elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty))

備註

GetCurrentPropertyValue方法所傳回的值在呼叫時是最新的。The value returned by the GetCurrentPropertyValue method is current at the time it is called. 此值隨後會由與互動的UIUI其他應用程式變更。The value can subsequently change by other applications interacting with the UIUI.

如果元素本身的使用者介面自動化提供者支援屬性,則會傳回屬性的值。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.

針對某些形式的UIUI,這個方法會產生跨進程的效能負擔。For some forms of UIUI, this method will incur cross-process performance overhead. 藉由快取屬性,然後使用GetCachedPropertyValue來抓取它們,來專注額外負荷。Concentrate overhead by caching properties and then retrieving them by using GetCachedPropertyValue.

GetCurrentPropertyValue(AutomationProperty, Boolean)

在此 AutomationElement 上擷取所指定屬性的值,選擇性忽略任何預設屬性。Retrieves the value of the specified property on this AutomationElement, optionally ignoring any default property.

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

參數

property
AutomationProperty

指定要擷取之屬性的 UI 自動化UI Automation 屬性識別碼。The UI 自動化UI Automation property identifier specifying which property to retrieve.

ignoreDefaultValue
Boolean

一個值,它指定若支援指定的屬性時是否應該忽略預設值。A value that specifies whether a default value should be ignored if the specified property is 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.

例外狀況

AutomationElement 的 UI 不再存在。The UI for the AutomationElement no longer exists.

範例

下列範例會抓取HelpText屬性的目前值,但指定如果元素本身不提供屬性的值,則會傳回, NotSupported而不是預設值。The following example retrieves the current value of the HelpText property, but specifies that if the element itself does not provide a value for the property, NotSupported is to be returned instead of a default value.

// elementList is an AutomationElement.
object help = elementList.GetCurrentPropertyValue(AutomationElement.HelpTextProperty, true);
if (help == AutomationElement.NotSupported)
{
    help = "No help available";
}
string helpText = (string)help;
' elementList is an AutomationElement.
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)

備註

傳入相當於呼叫AutomationElement.GetCurrentPropertyValue(AutomationProperty)false ignoreDefaultValuePassing false in ignoreDefaultValue is equivalent to calling AutomationElement.GetCurrentPropertyValue(AutomationProperty).

如果元素本身的使用者介面自動化提供者支援屬性,則會傳回屬性的值。If the UI Automation provider for the element itself supports the property, the value of the property is returned. 否則,如果ignoreDefaultValuefalseUI 自動化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.

GetCurrentPropertyValue方法所傳回的值在呼叫時是最新的。The value returned by the GetCurrentPropertyValue method is current at the time it is called. 此值隨後會由與互動的使用者介面 (UI)user interface (UI)其他應用程式變更。The value can subsequently change by other applications interacting with the 使用者介面 (UI)user interface (UI).

針對某些形式的UIUI,這個方法會產生跨進程的效能負擔。For some forms of UIUI, this method will incur cross-process performance overhead. 應用程式可以藉由快取屬性,然後使用GetCachedPropertyValue來抓取它們,來專注額外負荷。Applications can concentrate overhead by caching properties and then retrieving them by using GetCachedPropertyValue.

適用於