TreeWalker.ContentViewWalker Field

Represents a predefined TreeWalker containing a view of elements in the tree that are marked as content controls.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public static readonly TreeWalker ContentViewWalker

If your client application might try to find elements in its own user interface, you must make all UI Automation calls on a separate thread.

The following example shows ControlViewWalker being used to construct a tree view of elements in a subtree. The usage for ContentViewWalker is identical.

/// <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);
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft