IRawElementProviderFragmentRoot.GetFocus Method ()

 

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

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

IRawElementProviderFragment GetFocus()

Return Value

Type: System.Windows.Automation.Provider.IRawElementProviderFragment

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

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.

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;
}

.NET Framework
Available since 3.0
Return to top
Show: