0

I have got user control which have a popup (it is bigger than user control) Now I want to hide popup when user clicks in another part of a screen. (standard combobox behavior) How I can do this? I have tried to listen event pointer_click and I could get coordinates but it would be hard to manually check if user clicked on popup (maybe is there a way to check what control is on that coordinates?)

Thanks in advance

Krzysztof Kaczor
  • 5,408
  • 7
  • 39
  • 47
  • See [this](http://stackoverflow.com/questions/45813/wpf-get-elements-under-mouse) question – dvvrd Aug 23 '12 at 13:03

2 Answers2

1

If this a WinRT app then simply

var popup = new Popup();
popup.IsLightDismissEnabled = true;

If normal xaml then why not dismiss as soon as you lose focus?

AlSki
  • 6,868
  • 1
  • 26
  • 39
0

You have a few possibilities: -Use the VisualTree.Hittest method to get all controls of that point: if the result does not contain the popup hide it -If you have sender object (or a RoutedEventArgs object) you can use the VisualTree to lookup for the popup. (rekursiv) if you dont find it -> hide it

Florian
  • 5,918
  • 3
  • 47
  • 86