I think this is what's happening. You're showing a message, but immediately giving focus to the textbox again. Now, you have the message box open, and you want to click ok to close it, but then the textbox is losing focus again.
Maybe try the following:
private void TxtWONumber_LostFocus(object sender, RoutedEventArgs e)
{
if (checkNumber)
{
checkNumber = false;
string strWONumber = this.txtWONumber.Text;
var qryWorkOrder =
(from w in dataEntities.vwWOPatternCheckDatas
where w.WONumber == strWONumber
orderby w.WONumber
select new { w.WONumber }).ToList();
if (qryWorkOrder.Count() == 0)
{
if (MessageBox.Show("Work Order Number not found! Please enter a valid Work Order Number.") == DialogResult.OK)
{
txtWONumber.Focus();
txtWONumber.SelectAll();
checkNumber = true;
}
}
}
}
So, you have a
global bool variable checkNumber which is set to true, that indicates that you want to check the works order number. Once it enters the if statement, you set it to false, and set it back to true after you've clicked the ok button on the message box.