Redigera

Dela via


IRawElementProviderFragmentRoot.GetFocus Method

Definition

Retrieves the element in this fragment that has the input focus.

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

Returns

The provider for the element in this fragment that has the input focus, if any; otherwise, a null reference (Nothing in Visual Basic).

Examples

The following code example shows one possible implementation of this method for a list box. It returns the currently selected item in the list.

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

Remarks

If the focus is on an element in another framework that is hosted by this fragment, the method returns the element that hosts that fragment.

Applies to

See also