forum

Home / DeveloperSection / Forums / The difference between GotFocus and GotKeyboardFocus in wpf?

The difference between GotFocus and GotKeyboardFocus in wpf?

Anonymous User677310-Aug-2013

What is the difference(s) between GotFocus and GotKeyboardFocus -and similarly LostFocus and LostKeyboardFocus?

I am creating a custom control by extending Control class. Something like ComboBox but with some other effects. I'm trying to open and close a Popup by setting a property: IsDropDownOpen just like a ComboBox through the GotFocus and LostFocus events. I don't want to Popup get closed, when I Alt+Tabed the windows, but get closed when I click on a Button for example or I go to a TextBox. I did:

 

private static void OnGotFocusHandler(object sender, RoutedEventArgs e) {

    if (e.Handled)

        return;

    ((SearchBox)sender).IsDropDownOpen = true;

    e.Handled = true;

}

 

private static void OnLostFocusHandler(object sender, RoutedEventArgs e) {

    if (e.Handled)

        return;

    ((SearchBox)sender).IsDropDownOpen = false;

    e.Handled = true;

}

 

The GotFocus works. But the Lost one didn't. If I do the Lost stuff in LostKeyboardFocus then when I Alt+Tab the windows, or Window goes to inactive, then the method get called, while I don't want. How can I solve it?


Updated on 10-Aug-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By