Idioma

TreeWalker.GetParent Método

Definição

Recupera o elemento pai do AutomationElement.

Sobrecargas

Nome Description
GetParent(AutomationElement)

Recupera o elemento pai do AutomationElement.

GetParent(AutomationElement, CacheRequest)

Recupera o elemento pai das propriedades e padrões especificados AutomationElement e em cache.

Comentários

A estrutura da AutomationElement árvore muda conforme os elementos de interface do usuário (interface do usuário) visíveis na área de trabalho são alterados. Não é garantido que um elemento retornado como o elemento pai será retornado como o pai em passagens subsequentes.

GetParent(AutomationElement)

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

Retornos

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 estiver visível no modo de exibição atual.

Exemplos

O exemplo a seguir mostra GetParent como ser usado para localizar o elemento de 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

Confira também

Aplica-se a

GetParent(AutomationElement, CacheRequest)

Recupera o elemento pai das propriedades e padrões especificados AutomationElement e em 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

Parâmetros

element
AutomationElement

O elemento cujo pai deve ser retornado.

request
CacheRequest

Um objeto de solicitação de cache que especifica membros no cache retornado AutomationElement .

Retornos

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 estiver visível nessa exibição.

Comentários

A estrutura da AutomationElement árvore muda conforme os elementos de interface do usuário (interface do usuário) visíveis na área de trabalho são alterados. Não é garantido que um elemento retornado como o elemento pai será retornado como o pai em passagens subsequentes.

Confira também

Aplica-se a