I check the validity of the entered data in the LostFocus event (by the way, no one knows how to do it better? It was impossible to enter incorrect data in general, such as MaskedTextBox from Windows Forms.) And if incorrect data is entered, then I display an error and want to set the focus back. But instead, I have some sort of endless recursion and throws out the stack overflow error.
private void tbBottom_LostFocus(object sender, RoutedEventArgs e) { var value = 0.0; if (!double.TryParse(tbBottom.Text, out value) || value < 0 || value > 10000 || BottomValue >= TopValue) { MessageBox.Show("Incorrectly set. The value must adhere to the following rules: Bottom >= 0 && Bottom < 10000 && Bottom < Top.", "Setting error!", MessageBoxButton.OK, MessageBoxImage.Error); tbBottom.Focus(); return; } BottomValue = value; }