AutomationElement.GetCurrentPropertyValue 方法

定義

AutomationElement 擷取所指定屬性的目前值。

多載

GetCurrentPropertyValue(AutomationProperty)

在此 AutomationElement 上擷取所指定屬性的值。 針對目標使用者介面 (UI) 元素未明確支援的屬性,會傳回屬性類型的適當預設值。

GetCurrentPropertyValue(AutomationProperty, Boolean)

在此 AutomationElement 上擷取所指定屬性的值,選擇性忽略任何預設屬性。

備註

方法所 GetCurrentPropertyValue 傳回的值在呼叫時為目前值。 值後續可以由與使用者介面互動的其他應用程式 (UI) 變更。

對於某些形式的 UI,此方法會產生跨進程效能額外負荷。 應用程式可以藉由快取屬性,然後使用 來擷取額外 GetCachedPropertyValue 負荷。

GetCurrentPropertyValue(AutomationProperty)

在此 AutomationElement 上擷取所指定屬性的值。 針對目標使用者介面 (UI) 元素未明確支援的屬性,會傳回屬性類型的適當預設值。

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 自動化屬性識別碼,指定要擷取的屬性。

傳回

包含所指定屬性之值的物件。

例外狀況

範例

下列範例會擷取 屬性的 HelpText 目前值。 如果專案未提供預設值,則會傳回預設值。

// 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 傳回的值在呼叫時為目前值。 值後續可以由與 UI 互動的其他應用程式變更。

如果專案本身的 UI 自動化提供者支援 屬性,則會傳回 屬性的值。 否則,會傳回 UI 自動化所指定的預設屬性。 如需預設屬性的資訊,請參閱 的屬性識別碼欄位 AutomationElement ,例如 AcceleratorKeyProperty

對於某些形式的 UI,此方法會產生跨進程效能額外負荷。 藉由快取屬性,然後使用 擷取它們 GetCachedPropertyValue 來集中負荷。

適用於

GetCurrentPropertyValue(AutomationProperty, Boolean)

在此 AutomationElement 上擷取所指定屬性的值,選擇性忽略任何預設屬性。

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 自動化屬性識別碼,指定要擷取的屬性。

ignoreDefaultValue
Boolean

一個值,它指定若支援指定的屬性時是否應該忽略預設值。

傳回

包含所指定屬性的物件,或者若元素未提供值且 ignoreDefaultValuetrue,則是 NotSupported

例外狀況

範例

下列範例會擷取屬性的目前值 HelpText ,但指定如果專案本身未提供屬性的值, NotSupported 則會傳回 而不是預設值。

// 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)

備註

傳入 falseignoreDefaultValue 相當於呼叫 AutomationElement.GetCurrentPropertyValue(AutomationProperty)

如果專案本身的 UI 自動化提供者支援 屬性,則會傳回 屬性的值。 否則,如果 ignoreDefaultValuefalse ,則會傳回 UI 自動化所指定的預設屬性。 如需預設屬性的資訊,請參閱 的屬性識別碼欄位 AutomationElement ,例如 AcceleratorKeyProperty

方法所 GetCurrentPropertyValue 傳回的值在呼叫時為目前值。 值後續可以由與使用者介面互動的其他應用程式 (UI) 變更。

對於某些形式的 UI,此方法會產生跨進程效能額外負荷。 應用程式可以藉由快取屬性,然後使用 來擷取額外 GetCachedPropertyValue 負荷。

適用於