private void IgnoreIfUnfocused(object sender, MouseEventArgs e) { if (sender is TextBox textBox) { if (!textBox.IsKeyboardFocusWithin) { textBox.Focus(); e.Handled = true; } } } }