LosingFocusEventArgs.TrySetNewFocusedElement(DependencyObject) LosingFocusEventArgs.TrySetNewFocusedElement(DependencyObject) LosingFocusEventArgs.TrySetNewFocusedElement(DependencyObject) LosingFocusEventArgs.TrySetNewFocusedElement(DependencyObject) Method

Definition

Attempts to redirect focus from the targeted element to the specified element.

public : Platform::Boolean TrySetNewFocusedElement(DependencyObject element)
bool TrySetNewFocusedElement(DependencyObject element) const;
public bool TrySetNewFocusedElement(DependencyObject element)
Public Function TrySetNewFocusedElement(element As DependencyObject) As bool

Parameters

element
DependencyObject DependencyObject

The object on which to set focus.

Returns

bool bool

True, if the focus action is redirected; otherwise, false.

Additional features and requirements

Device family
Windows 10, version 1803 (introduced v10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v6)

Remarks

The GotFocus routed event is raised on an element after it receives focus, while the LostFocus routed event is raised on an element after it loses focus.

The GettingFocus and LosingFocus routed events occur before the focus change takes place, which enables your application to modify or cancel the focus change behavior.

GettingFocus and LosingFocus are raised synchronously, while GotFocus and LostFocus are raised asynchronously. For example, if your app calls the Focus method of a control, GettingFocus is raised during the call, but GotFocus is raised after the call completes.

If focus is moved while these events are still bubbling, an exception is thrown.

See also