AutomationElement.Current 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 AutomationElement 的当前属性值。
public:
property System::Windows::Automation::AutomationElement::AutomationElementInformation Current { System::Windows::Automation::AutomationElement::AutomationElementInformation get(); };
public System.Windows.Automation.AutomationElement.AutomationElementInformation Current { get; }
member this.Current : System.Windows.Automation.AutomationElement.AutomationElementInformation
Public ReadOnly Property Current As AutomationElement.AutomationElementInformation
属性值
一个包含当前属性值的结构。
例外
AutomationElement 的 UI 不再存在。
示例
以下示例演示如何 Current 使用该属性检索列表中选定的项的名称。
/// <summary>
/// Handles ElementSelected events by showing a message.
/// </summary>
/// <param name="src">Object that raised the event; in this case, a list item.</param>
/// <param name="e">Event arguments.</param>
private void OnSelect(object src, AutomationEventArgs e)
{
// Get the name of the item, which is equivalent to its text.
AutomationElement element = src as AutomationElement;
if (element != null)
{
Console.WriteLine(element.Current.Name + " was selected.");
}
}
''' <summary>
''' Handles ElementSelected events by showing a message.
''' </summary>
''' <param name="src">Object that raised the event; in this case, a list item.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnSelect(ByVal src As Object, ByVal e As AutomationEventArgs)
' Get the name of the item, which is equivalent to its text.
Dim element As AutomationElement = DirectCast(src, AutomationElement)
If (element IsNot Nothing) Then
Console.WriteLine(element.Current.Name + " was selected.")
End If
End Sub
注解
UI 自动化属性的访问器表示为返回Current的结构的属性。 无需检索结构;可以直接访问其成员,如以下示例所示。 有关可用属性及其使用的具体信息,请参阅 AutomationElement.AutomationElementInformation。
若要获取此元素上UI 自动化属性的缓存值,请使用该Cached属性。