TreeWalker(Condition) Konstruktor

Definition

Initialisiert eine neue Instanz der TreeWalker-Klasse.

public:
 TreeWalker(System::Windows::Automation::Condition ^ condition);
public TreeWalker (System.Windows.Automation.Condition condition);
new System.Windows.Automation.TreeWalker : System.Windows.Automation.Condition -> System.Windows.Automation.TreeWalker
Public Sub New (condition As Condition)

Parameter

condition
Condition

Die Ansicht der Benutzeroberflächenautomatisierung Elementstruktur, die TreeWalker navigiert wird.

Beispiele

Das folgende Beispiel zeigt, wie Sie ein TreeWalker Objekt erstellen können, das nur zwischen aktivierten Elementen navigiert.

/// <summary>
/// Walks the UI Automation tree and adds the control type of each enabled control 
/// element it finds to a TreeView.
/// </summary>
/// <param name="rootElement">The root of the search on this iteration.</param>
/// <param name="treeNode">The node in the TreeView for this iteration.</param>
/// <remarks>
/// This is a recursive function that maps out the structure of the subtree beginning at the
/// UI Automation element passed in as rootElement on the first call. This could be, for example,
/// an application window.
/// CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
/// the desktop could take a very long time and even lead to a stack overflow.
/// </remarks>
private void WalkEnabledElements(AutomationElement rootElement, TreeNode treeNode)
{
    Condition condition1 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
    Condition condition2 = new PropertyCondition(AutomationElement.IsEnabledProperty, true);
    TreeWalker walker = new TreeWalker(new AndCondition(condition1, condition2));
    AutomationElement elementNode = walker.GetFirstChild(rootElement);
    while (elementNode != null)
    {
        TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);
        WalkEnabledElements(elementNode, childTreeNode);
        elementNode = walker.GetNextSibling(elementNode);
    }
}
''' <summary>
''' Walks the UI Automation tree and adds the control type of each enabled control 
''' element it finds to a TreeView.
''' </summary>
''' <param name="rootElement">The root of the search on this iteration.</param>
''' <param name="treeNode">The node in the TreeView for this iteration.</param>
''' <remarks>
''' This is a recursive function that maps out the structure of the subtree beginning at the
''' UI Automation element passed in as rootElement on the first call. This could be, for example,
''' an application window.
''' CAUTION: Do not pass in AutomationElement.RootElement. Attempting to map out the entire subtree of
''' the desktop could take a very long time and even lead to a stack overflow.
''' </remarks>
Private Sub WalkEnabledElements(ByVal rootElement As AutomationElement, ByVal treeNode As TreeNode)
    Dim condition1 As New PropertyCondition(AutomationElement.IsControlElementProperty, True)
    Dim condition2 As New PropertyCondition(AutomationElement.IsEnabledProperty, True)
    Dim walker As New TreeWalker(New AndCondition(condition1, condition2))
    Dim elementNode As AutomationElement = walker.GetFirstChild(rootElement)
    While (elementNode IsNot Nothing)
        Dim childTreeNode As TreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType)
        WalkEnabledElements(elementNode, childTreeNode)
        elementNode = walker.GetNextSibling(elementNode)
    End While

End Sub

Hinweise

Benutzeroberflächenautomatisierung Elemente, die nicht übereinstimmencondition, werden übersprungen, wenn TreeWalker sie zum Navigieren in der Elementstruktur verwendet werden.

Wenn Ihre Clientanwendung möglicherweise versucht, Elemente in einer eigenen Benutzeroberfläche zu finden, müssen Sie alle Benutzeroberflächenautomatisierung Aufrufe an einem separaten Thread vornehmen.

Gilt für

Siehe auch