Partilhar via


PendingFocusHelper.SetFocusOnLoad Method

Definition

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.

Applies to