.net – GotFocus and LostFocus Events in WPF TextBox

.net-4.0bindingnetwpf

I have a textBox control in a WPF window. I have separate handlers for GotFocus and LostFocus events. But when the textbox attains focus for the first time LostFocus is invoked after GotFous (The textbox loses focus as soon as it attains focus for the first time) . But this doesn't happen when the textBox attains focus for the second time.

Best Answer

Sounds like maybe something is happening during the GotFocus event handler (or deeper in the call stack) that is relinquishing focus to another control.

You might want to try setting a breakpoint in your LostFocus event handler and then look at the call stack to see if something is setting the focus elsewhere either directly or indirectly.