TreeWalker.GetParent Metodo

Definizione

Recupera l'elemento padre dell'oggetto specificato AutomationElement.

Overload

Nome Descrizione
GetParent(AutomationElement)

Recupera l'elemento padre dell'oggetto specificato AutomationElement.

GetParent(AutomationElement, CacheRequest)

Recupera l'elemento padre delle proprietà e dei modelli specificati AutomationElement e memorizzati nella cache.

Commenti

La struttura dell'albero AutomationElement cambia man mano che cambiano gli elementi dell'interfaccia utente visibile sul desktop. Non è garantito che un elemento restituito come elemento padre venga restituito come elemento padre nei passaggi successivi.

GetParent(AutomationElement)

Recupera l'elemento padre dell'oggetto specificato 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

Parametri

element
AutomationElement

Elemento il cui elemento padre deve essere restituito.

Valori restituiti

L'elemento padre o un riferimento Null (Nothing in Visual Basic) se l'elemento specificato è l'elemento radice nell'albero o se l'elemento padre non è visibile nella visualizzazione corrente.

Esempio

Nell'esempio seguente viene illustrato GetParent l'utilizzo per trovare l'elemento window che contiene un elemento specificato.

/// <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

Vedi anche

Si applica a

GetParent(AutomationElement, CacheRequest)

Recupera l'elemento padre delle proprietà e dei modelli specificati AutomationElement e memorizzati nella cache.

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

Parametri

element
AutomationElement

Elemento il cui elemento padre deve essere restituito.

request
CacheRequest

Oggetto richiesta cache che specifica i membri nella cache restituiti AutomationElement .

Valori restituiti

L'elemento padre o un riferimento Null (Nothing in Visual Basic) se l'elemento specificato è l'elemento radice nell'albero o l'elemento padre non è visibile in questa visualizzazione.

Commenti

La struttura dell'albero AutomationElement cambia man mano che cambiano gli elementi dell'interfaccia utente visibile sul desktop. Non è garantito che un elemento restituito come elemento padre venga restituito come elemento padre nei passaggi successivi.

Vedi anche

Si applica a