PendingFocusHelper.SetFocusOnLoad 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.
Either sends focus to the FrameworkElement immediately using Focus, or delays focusing the FrameworkElement until it is loaded. The last element pending focus on Loaded will be focused, and all previous FrameworkElements will not be focused.
If UIElement.MoveFocus fails to move focus into the element, focus will be cleared by invoking Keyboard.ClearFocus to clear WPF focus, and by using SetFocus to focus the HWND of HwndSource containing the element.
public static void SetFocusOnLoad (System.Windows.FrameworkElement element, Action<System.Windows.FrameworkElement> focusAction = default);
static member SetFocusOnLoad : System.Windows.FrameworkElement * Action<System.Windows.FrameworkElement> -> unit
Public Shared Sub SetFocusOnLoad (element As FrameworkElement, Optional focusAction As Action(Of FrameworkElement) = Nothing)
Parameters
- element
- FrameworkElement
The element to focus.
- focusAction
- Action<FrameworkElement>
The method that will set the focus to the element.
If null, MoveFocusInto(UIElement) will be used.
Remarks
Either sends focus to the FrameworkElement immediately using Focus, or delays focusing the FrameworkElement until it is loaded. The last element pending focus on Loaded will be focused, and all previous FrameworkElements will not be focused. If UIElement.MoveFocus fails to move focus into the element, focus will be cleared by invoking Keyboard.ClearFocus to clear WPF focus, and by using SetFocus to focus the HWND of HwndSource containing the element.