TreeWalker.GetParent 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取指定 AutomationElement的父元素。
多載
| 名稱 | Description |
|---|---|
| GetParent(AutomationElement) |
擷取指定 AutomationElement的父元素。 |
| GetParent(AutomationElement, CacheRequest) |
擷取指定的 AutomationElement 父元素並快取屬性與模式。 |
備註
樹狀 AutomationElement 結構會隨著桌面上可見的使用者介面(UI)元素變化而改變。 不保證以父元素回傳的元素會在後續執行中回傳為父元素。
GetParent(AutomationElement)
擷取指定 AutomationElement的父元素。
public:
System::Windows::Automation::AutomationElement ^ GetParent(System::Windows::Automation::AutomationElement ^ element);
public System.Windows.Automation.AutomationElement GetParent(System.Windows.Automation.AutomationElement element);
member this.GetParent : System.Windows.Automation.AutomationElement -> System.Windows.Automation.AutomationElement
Public Function GetParent (element As AutomationElement) As AutomationElement
參數
- element
- AutomationElement
要返回父元素的元素。
傳回
若指定元素是樹中的根元素,或父元素在目前視圖中不可見,則稱為空參考(
範例
以下範例展示了 GetParent 如何用來尋找包含指定元素的視窗元素。
/// <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;
do
{
elementParent = walker.GetParent(node);
if (elementParent == AutomationElement.RootElement) break;
node = elementParent;
}
while (true);
return node;
}
''' <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 Function GetTopLevelWindow(ByVal element As AutomationElement) As AutomationElement
Dim walker As TreeWalker = TreeWalker.ControlViewWalker
Dim elementParent As AutomationElement
Dim node As AutomationElement = element
If node = elementRoot Then
Return node
End If
Do
elementParent = walker.GetParent(node)
If elementParent = AutomationElement.RootElement Then
Exit Do
End If
node = elementParent
Loop While True
Return node
End Function 'GetTopLevelWindow
End Class
另請參閱
適用於
GetParent(AutomationElement, CacheRequest)
擷取指定的 AutomationElement 父元素並快取屬性與模式。
public:
System::Windows::Automation::AutomationElement ^ GetParent(System::Windows::Automation::AutomationElement ^ element, System::Windows::Automation::CacheRequest ^ request);
public System.Windows.Automation.AutomationElement GetParent(System.Windows.Automation.AutomationElement element, System.Windows.Automation.CacheRequest request);
member this.GetParent : System.Windows.Automation.AutomationElement * System.Windows.Automation.CacheRequest -> System.Windows.Automation.AutomationElement
Public Function GetParent (element As AutomationElement, request As CacheRequest) As AutomationElement
參數
- element
- AutomationElement
要返回父元素的元素。
- request
- CacheRequest
一個快取請求物件,指定返回 AutomationElement 快取的成員。
傳回
若指定元素是樹中的根元素,或在此視圖中看不到父元素,則稱為空參考(Visual BasicNothing)。
備註
樹狀 AutomationElement 結構會隨著桌面上可見的使用者介面(UI)元素變化而改變。 不保證以父元素回傳的元素會在後續執行中回傳為父元素。