2

I am trying to perform some custom validation inside the c1 masked textbox and the validation has to occur OnLostFocus(). The problem is, when im calling Focus() from within OnLostFocus(), its causing the control to lose/gain focus again which is infinite looping. Any help/suggestions would be great!

thanks in advance!!!

below is basically the code behind what I have:

    protected override void OnLostFocus(RoutedEventArgs e)
    {

        if (!CheckAndRunValidator())
        {
            Focus();
            SelectAll();

            return;
        }

        base.OnLostFocus(e);

    }
spyter
  • 727
  • 1
  • 9
  • 25

1 Answers1

1

You could try

Dispatcher.BeginInvoke( () => Focus() );

If that does not work try using a DispatcherTimer with a short Interval and do the focus int the Tick event.

Wolfgang Ziegler
  • 1,675
  • 11
  • 23
  • if (!CheckAndRunValidator()) { var dispatcherTimer = new DispatcherTimer {Interval = new TimeSpan(300)}; dispatcherTimer.Tick += (sender, args) => { Dispatcher.BeginInvoke(() => Focus()); dispatcherTimer.Stop(); }; dispatcherTimer.Start(); } – spyter Aug 01 '12 at 16:15