TreeWalker.ContentViewWalker 필드

정의

콘텐츠 컨트롤로 표시된 트리의 요소 뷰를 포함하는 미리 정의된 TreeWalker 형식을 나타냅니다.

public: static initonly System::Windows::Automation::TreeWalker ^ ContentViewWalker;
public static readonly System.Windows.Automation.TreeWalker ContentViewWalker;
 staticval mutable ContentViewWalker : System.Windows.Automation.TreeWalker
Public Shared ReadOnly ContentViewWalker As TreeWalker 

필드 값

예제

다음 예제에서는 하위 트리에서 요소의 트리 뷰를 생성하는 데 사용되는 방법을 보여 ControlViewWalker 있습니다. 사용 ContentViewWalker 법은 동일합니다.

/// <summary>
/// Walks the UI Automation tree and adds the control type of each element it finds 
/// in the control view 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 WalkControlElements(AutomationElement rootElement, TreeNode treeNode)
{
    // Conditions for the basic views of the subtree (content, control, and raw) 
    // are available as fields of TreeWalker, and one of these is used in the 
    // following code.
    AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(rootElement);

    while (elementNode != null)
    {
        TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);
        WalkControlElements(elementNode, childTreeNode);
        elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
    }
}
''' <summary>
''' Walks the UI Automation tree and adds the control type of each element it finds 
''' in the control view 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 WalkControlElements(ByVal rootElement As AutomationElement, ByVal treeNode As TreeNode)
    ' Conditions for the basic views of the subtree (content, control, and raw) 
    ' are available as fields of TreeWalker, and one of these is used in the 
    ' following code.
    Dim elementNode As AutomationElement = TreeWalker.ControlViewWalker.GetFirstChild(rootElement)

    While (elementNode IsNot Nothing)
        Dim childTreeNode As TreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType)
        WalkControlElements(elementNode, childTreeNode)
        elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode)
    End While

End Sub

설명

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

적용 대상

추가 정보