Search code examples
c#wpfpopup

How to get back the focus on popup, after losing it in WPF?


I have a main window, If I click a certain button, I have a popUp window, that pops up with few different component (input, button, dropdownlist etc) on it. Everything works fine, until I lose focus by simply clicking outside. And if I want to come back, I click back on Popup, but it can't be active again, and for that to be active, I have to click on the Main window, or to click on the appIcon on the taskBar.

Have you guys ever had such problem?

And How to resolve it?

Thank you!


Solution

  • I think you are looking for PreviewMouseDown event. I have tested it and it does recover lost focus.

    private void Popup_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        this.Focus();
    }