现在光标聚焦在 TextBox 中。如果我点击按钮 (RemoveLostFocus),TextBox 的 Lost focus 事件会被触发。但我需要的是,TextBox 的 Lost Focus 事件不应该触发。有什么办法吗?
private void Window_Loaded(object sender, RoutedEventArgs e)
{
txtUserName.Focus();
}
private void UserName_LostFocus(object sender, RoutedEventArgs e)
{
if (txtUserName.Text.Length < 1)
{
MessageBox.Show("UserName should not be empty");
}
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
anotherWindow.Show();
}