AutomationElement.RootElement 屬性

定義

取得目前桌面的根 AutomationElementGets the root AutomationElement for the current desktop.

public:
 static property System::Windows::Automation::AutomationElement ^ RootElement { System::Windows::Automation::AutomationElement ^ get(); };
public static System.Windows.Automation.AutomationElement RootElement { get; }
member this.RootElement : System.Windows.Automation.AutomationElement
Public Shared ReadOnly Property RootElement As AutomationElement

屬性值

AutomationElement

根項目。The root element.

範例

下列範例程式碼會抓取桌面所有直屬子系的集合。The following example code retrieves a collection of all the immediate children of the desktop.

AutomationElementCollection desktopChildren =
    AutomationElement.RootElement.FindAll(
    TreeScope.Children, Condition.TrueCondition);
Dim desktopChildren As AutomationElementCollection
desktopChildren = AutomationElement.RootElement.FindAll( _
    TreeScope.Children, Condition.TrueCondition)

備註

您可以使用根項目作為尋找其他元素的起點,方法是使用 FindAllFindFirst 方法。You can use the root element as a starting point for finding other elements, using the FindAll and FindFirst methods.

從根項目搜尋時,請務必 Children 在搜尋範圍中指定,而不是在搜尋範圍中指定 DescendantsWhen searching from the root element, be sure to specify Children in the scope of the search, not Descendants. 搜尋整個桌面的整個子樹可逐一查看數以千計的專案,並導致堆疊溢位。A search through the entire subtree of the desktop could iterate through thousands of items and lead to a stack overflow.

適用於