Encontrar um Elemento de Automação de Interface de Usuário para um Item de Lista
Este tópico mostra como recuperar um AutomationElement Para um item em uma lista quando o índice do item é conhecido.
Exemplo
O exemplo a seguir mostra duas maneiras de recuperar um item especificado em uma lista, uma com TreeWalker e os outros usando FindAll.
O Primeiro técnica tende a ser mais rápido para Win32 Controles, mas o segundo é mais rápido para Controles.
AutomationElement FindChildAt(AutomationElement parent, index)
{
(index < 0)
{
ArgumentOutOfRangeException();
}
TreeWalker walker = TreeWalker.ControlViewWalker;
AutomationElement child = walker.GetFirstChild(parent);
( x = 1; x <= index; x++)
{
child = walker.GetNextSibling(child);
(child == )
{
ArgumentOutOfRangeException();
}
}
child;
}
AutomationElement FindChildAtB(AutomationElement parent, index)
{
Condition findCondition = PropertyCondition(AutomationElement.IsControlElementProperty, );
AutomationElementCollection found = parent.FindAll(TreeScope.Children, findCondition);
((index < 0) || (index >= found.Count))
{
ArgumentOutOfRangeException();
}
found[index];
}
FindChildAt( parent AutomationElement, index ) AutomationElement
(index < 0)
ArgumentOutOfRangeException()
walker TreeWalker = TreeWalker.ControlViewWalker
child AutomationElement = walker.GetFirstChild(parent)
x = 1 (index - 1)
child = walker.GetNextSibling(child)
child =
ArgumentOutOfRangeException()
x
child
FindChildAtB( parent AutomationElement, index ) AutomationElement
findCondition Condition = _
PropertyCondition(AutomationElement.IsControlElementProperty, )
found AutomationElementCollection = parent.FindAll(TreeScope.Children, findCondition)
(index < 0) Or (index >= found.Count)
ArgumentOutOfRangeException()
found(index)