Method 1
setFocus(txts_StockNo);
//set focus
public static void setFocus(UIElement element)
{
if (!element.Focus())
{
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()
{
element.Focus();
}));
}
else
{
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()
{
element.Focus();
}));
}
}
Method 2
Write Down code on lost focus instead of PreviewLostKeyboardFocus_1
private void txtPhone_PreviewLostKeyboardFocus_1(object sender, KeyboardFocusChangedEventArgs e)
{
if (txtPhone.Value.ToString().Length < 10 && txtPhone.Value.ToString().Length != 0)
{
MessageBox.Show("Enter 10 digit home number", "DMS", MessageBoxButton.OK, MessageBoxImage.Exclamation);
//txtPhone.Focus();
e.Handled = true;
}
else
{
if (Convert.ToString(txtPhone.Value) != "")
{
//// wrote down ur code
}
}
setFocus(txts_StockNo);
//set focus
public static void setFocus(UIElement element)
{
if (!element.Focus())
{
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()
{
element.Focus();
}));
}
else
{
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()
{
element.Focus();
}));
}
}
Method 2
Write Down code on lost focus instead of PreviewLostKeyboardFocus_1
private void txtPhone_PreviewLostKeyboardFocus_1(object sender, KeyboardFocusChangedEventArgs e)
{
if (txtPhone.Value.ToString().Length < 10 && txtPhone.Value.ToString().Length != 0)
{
MessageBox.Show("Enter 10 digit home number", "DMS", MessageBoxButton.OK, MessageBoxImage.Exclamation);
//txtPhone.Focus();
e.Handled = true;
}
else
{
if (Convert.ToString(txtPhone.Value) != "")
{
//// wrote down ur code
}
}
0 comments:
Post a Comment