IRawElementProviderFragmentRoot.GetFocus Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈