Need some help.
Keep Focus back to the previous Textbox on failed validation
1917
26-Mar-2014
I
want Focus back to the previous Textbox if validation gets failed. I am
validating the Textbox control value on lostFocus event.
Pravesh Singh
26-Mar-2014If you attempt to focus an element inside its own LostFocus handler you will face a StackOverflowException, I'm not sure about the root cause (I suspect the focus kind of bounces around) but there is an easy workaround: dispatch it.
Through Dispatcher.BeginInvoke you make sure that restoring the focus doesn't get in the way of the in-progress loss of focus (and avoid the nasty exception you'd face otherwise)