LostFocus, StackOverflowException, ( , ), : .
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
var element = (sender as TextBox);
if (!theTextBoxWasValidated())
{
var restoreFocus = (System.Threading.ThreadStart)delegate { element.Focus(); };
Dispatcher.BeginInvoke(restoreFocus);
}
}
Through Dispatcher.BeginInvoke, you can make sure that focus recovery does not interfere with the current focus (and avoid an unpleasant exception that you would otherwise encounter)
source
share