TreeWalker.GetParent Método

Definição

Recupera o elemento pai do especificado AutomationElement.

Sobrecargas

Name Description
GetParent(AutomationElement)

Recupera o elemento pai do especificado AutomationElement.

GetParent(AutomationElement, CacheRequest)

Recupera o elemento pai do especificado AutomationElement e armazena em cache propriedades e padrões.

Observações

A estrutura da AutomationElement árvore muda à medida que os elementos visíveis da interface de utilizador (UI) no ambiente de trabalho mudam. Não é garantido que um elemento devolvido como elemento pai será devolvido como pai em passagens subsequentes.

GetParent(AutomationElement)

Recupera o elemento pai do especificado 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

Parâmetros

element
AutomationElement

O elemento cujo pai deve ser devolvido.

Devoluções

O elemento pai, ou uma referência nula (Nothing em Visual Basic) se o elemento especificado for o elemento raiz na árvore, ou se o elemento pai não for visível na vista atual.

Exemplos

O exemplo seguinte mostra GetParent ser usado para encontrar o elemento janela que contém um elemento especificado.

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

Ver também

Aplica-se a

GetParent(AutomationElement, CacheRequest)

Recupera o elemento pai do especificado AutomationElement e armazena em cache propriedades e padrões.

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

Parâmetros

element
AutomationElement

O elemento cujo pai deve ser devolvido.

request
CacheRequest

Um objeto de pedido de cache que especifica membros no cache retornado AutomationElement .

Devoluções

O elemento pai, ou uma referência nula (Nothing em Visual Basic) se o elemento especificado for o elemento raiz na árvore, ou se o elemento pai não for visível nesta vista.

Observações

A estrutura da AutomationElement árvore muda à medida que os elementos visíveis da interface de utilizador (UI) no ambiente de trabalho mudam. Não é garantido que um elemento devolvido como elemento pai será devolvido como pai em passagens subsequentes.

Ver também

Aplica-se a