LostFocus not firing when parent loses focus

3 posts, 0 answers
  1. Einar
    Einar avatar
    19 posts
    Member since:
    Jul 2014

    Posted 08 Jun 2015 Link to this post

    I have an issue where if I click on controls outside of the Window that contains my MaskedTextInput the LostFocus event doesn't fire. The control is technically working correctly, but I believe what I'm really after is something such as LostKeyboardFocus (but that option doesn't exist in the databinding.

    Unfortunately using PropertyChanged event is not an option in my case. Thoughts?

    I'm committing the value like so: 

    Value="{Binding BusinessPostalCode, UpdateSourceTrigger=LostFocus}"

  2. Sia
    Sia avatar
    667 posts

    Posted 10 Jun 2015 Link to this post

    Hello Einar,

    Unfortunately you cannot use the LostFocus event for this purpose. If you test the same behavior when using TextBox instead of MaskedTextInput, you will see that again the LostFocus event is not fired if you click outside the Window. Every application/window has its own Keyboard Focus and when you click outside it and after that again on it the focused element is preserved. That is why the LostFocus is not fired.

    What I can suggest is to use the Window Deactivated event and check whether the focus is on the MaskedTextInput:
    private void Window_Deactivated(object sender, EventArgs e)
        if (this.Mask.IsKeyboardFocusWithin)

    You need to implement some custom logic depending on your requirements.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Einar
    Einar avatar
    19 posts
    Member since:
    Jul 2014

    Posted 14 Oct 2015 in reply to Sia Link to this post

    Thanks for your suggestion Sia, I ended up just adding a LostKeyboardFocus event handler and manually set my view model property to the Value property for the control. It seems to work well.
Back to Top