1

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!

Ming
  • 141
  • 9

1 Answers1

0

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.

trinaldi
  • 2,872
  • 2
  • 32
  • 37
  • Thanks for the reply Tico, but that's not exactly what I am looking for. – Ming Oct 02 '13 at 18:13
  • Suppose I want to click on another control (any other control), I want to know what that control is, while code is still running within the PreviewLoseKeyboardFocus handler method. I don't think tabIndex will help me in this case. As for the textbox.IsFocused property, I verified the value in the debug mode(inside of the textbox_PreviewLostKeyboardFocus() event handler), and the property returns false. Nevertheless, thank you so much! – Ming Oct 02 '13 at 18:21
  • Sorry I couldn't help you properly! – trinaldi Oct 02 '13 at 18:23