IRawElementProviderFragmentRoot.GetFocus Método

Definição

Recupera o elemento neste fragmento que tem o foco de entrada.

public:
 System::Windows::Automation::Provider::IRawElementProviderFragment ^ GetFocus();
public System.Windows.Automation.Provider.IRawElementProviderFragment GetFocus();
abstract member GetFocus : unit -> System.Windows.Automation.Provider.IRawElementProviderFragment
Public Function GetFocus () As IRawElementProviderFragment

Devoluções

O fornecedor do elemento neste fragmento que tem o foco de entrada, se existir; caso contrário, uma referência nula (Nothing em Visual Basic).

Exemplos

O exemplo de código seguinte mostra uma possível implementação deste método para uma caixa de lista. Devolve o item atualmente selecionado na lista.

/// <summary>
/// Returns the child element that is selected when the list gets focus.
/// </summary>
/// <returns>The selected item.</returns>
/// <remarks>
/// SelectedIndex is a class property that maintains the index of the currently
/// selected item in the myItems collection.</remarks>
IRawElementProviderFragment IRawElementProviderFragmentRoot.GetFocus()
{
    if (SelectedIndex >= 0)
    {
        return (IRawElementProviderFragment)myItems[SelectedIndex];
    }
    else
    {
        return null;
    }
}
''' <summary>
''' Returns the child element that is selected when the list gets focus.
''' </summary>
''' <returns>The selected item.</returns>
''' <remarks>
''' SelectedIndex is a class property that maintains the index of the currently
''' selected item in the myItems collection.</remarks>
Function GetFocus() As IRawElementProviderFragment _
    Implements IRawElementProviderFragmentRoot.GetFocus

    If SelectedIndex >= 0 Then
        Return DirectCast(myItems(SelectedIndex), IRawElementProviderFragment)
    Else
        Return Nothing
    End If
End Function 'IRawElementProviderFragmentRoot.GetFocus

Observações

Se o foco estiver num elemento de outra estrutura que é hospedado por esse fragmento, o método devolve o elemento que aloja esse fragmento.

Aplica-se a

Ver também