This is a migrated thread and some comments may be shown as answers.

LostFocus not firing when parent loses focus

2 Answers 2843 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Einar
Top achievements
Rank 1
Einar asked on 08 Jun 2015, 09:37 PM

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 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 10 Jun 2015, 04:02 PM
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.

Regards,
Sia
Telerik
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
0
Einar
Top achievements
Rank 1
answered on 14 Oct 2015, 03:00 PM
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.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Einar
Top achievements
Rank 1
Answers by
Sia
Telerik team
Einar
Top achievements
Rank 1
Share this question
or