AutomationElement.Current 属性

定义

获取 AutomationElement 的当前属性值。Gets the current property values of the 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

属性值

一个包含当前属性值的结构。A structure containing the current property values.

异常

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

示例

下面的示例演示如何Current使用属性来检索列表中已选择的项的名称。The following example shows how the Current property is used to retrieve the name of an item that has been selected in a list.

/// <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 自动化UI Automation属性的访问器表示为Current返回的结构的属性。The accessors for UI 自动化UI Automation properties are represented as properties of the structure returned by Current. 不需要检索结构;您可以直接访问其成员,如下面的示例中所示。You do not need to retrieve the structure; you can access its members directly, as in the example below. 有关可用属性及其用法的特定信息,请参阅AutomationElement.AutomationElementInformationFor specific information on the properties available and their use, see AutomationElement.AutomationElementInformation.

若要获取此元素的UI 自动化UI Automation属性的缓存值,请Cached使用属性。To get the cached value of UI 自动化UI Automation properties on this element, use the Cached property.

适用于

另请参阅