This documentation is archived and is not being maintained.

TreeWalker.GetParent Method (AutomationElement)

Retrieves the parent element of the specified AutomationElement.

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

public AutomationElement GetParent(
	AutomationElement element


Type: System.Windows.Automation.AutomationElement

The element whose parent is to be returned.

Return Value

Type: System.Windows.Automation.AutomationElement
The parent element, or a null reference (Nothing in Microsoft Visual Basic .NET) if the specified element is the root element in the tree, or if the parent element is not visible in the current view.

The following example shows GetParent being used to find the window element that contains a specified element.

/// <summary> 
/// Retrieves the top-level window that contains the specified UI Automation element. 
/// </summary> 
/// <param name="element">The contained element.</param>
/// <returns>The containing top-level window element.</returns> 
private AutomationElement GetTopLevelWindow(AutomationElement element)
    TreeWalker walker = TreeWalker.ControlViewWalker;
    AutomationElement elementParent;
    AutomationElement node = element;
    if (node == elementRoot) return node;
        elementParent = walker.GetParent(node);
        if (elementParent == AutomationElement.RootElement) break;
        node = elementParent;
    while (true);
    return node;

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