语言

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

一个值,该值指定是否应忽略默认值(如果支持指定的属性)。

返回

包含指定属性的值的对象,或者 NotSupported 元素不提供值且 ignoreDefaultValue 为 true。

例外

示例

下面的示例检索属性的 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来集中开销。

适用于