Επεξεργασία

Κοινή χρήση μέσω


AutomationElement.Current Property

Definition

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

Property Value

A structure containing the current property values.

Exceptions

The UI for the AutomationElement no longer exists.

Examples

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

Remarks

The accessors for 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. For specific information on the properties available and their use, see AutomationElement.AutomationElementInformation.

To get the cached value of UI Automation properties on this element, use the Cached property.

Applies to

See also