TreeWalker(Condition) 생성자

정의

TreeWalker 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

condition
Condition

탐색할 UI 자동화 요소 트리 TreeWalker 의 보기입니다.

예제

다음 예제에서는 어떻게 생성할 수 있습니다는 TreeWalker 간에 설정 된 요소를 탐색 합니다.

/// <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

설명

일치하지 condition 않는 UI 자동화 요소는 요소 트리를 탐색하는 데 사용될 때 TreeWalker 건너뜁습니다.

클라이언트 애플리케이션이 자체 사용자 인터페이스에서 요소를 찾으려고 할 수 있는 경우 별도의 스레드에서 모든 UI 자동화 호출을 수행해야 합니다.

적용 대상

추가 정보