WPF Find new focus control in PreviewLostKeyboardFocus

508 Views Asked by At

Is there a way to find the new focused control in the PreviewLostKeyboardFocus handler? For example, I have a textbox control with the PreviewLostKeyboardFocus event and I clicked on another control. Is there a way to find out what the new control is within the PreviewLostKeyboardFocus handler method?

The strange part is that textbox.IsFocused returns false, and FocusManager.GetFocusedElement(Application.Current.MainWindow) returns the current textbox control.

Many thanks in advence!

1

There are 1 best solutions below

3
trinaldi On

You should set the TabIndex property of your controls.
Supposedly, the next control to get the focus will be the one with the next TabIndex.

Regarding your next question, IsFocused is set at runtime. So, if you look at the TextBox properties with a debugger, you should see IsFocused true only when the keyboard is at it.