Getting the Popup to Close When It Loses Focus

On a recent project, I spent (I kid you not) over three hours trying to get a stinking popup to close when I clicked somewhere else in the application.

 Figuring it was a focus issue, I tried the following triggers:

  • IsFocused
  • IsKeyboardFocused
  • IsKeyboardFocusWithin
  • IsMouseCapture
  • IsMouseCaptureWithin

All to no avail.

Turns out that the only thing I had to do was set the StaysOpen property of the Popup thus:

<Popup StaysOpen=”False>

Handy little property. I just wish that it was the default.

5 thoughts on “Getting the Popup to Close When It Loses Focus

  1. works fine if your popup has no buttons, textboxes etc (popup closes as soon as you focus the button).

  2. Thank you very much. I just spent more than 3 hours on that, trying to handle all kinds of events in the world. Just found it. Thanks for sharing.

Comments are closed.