Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all opened Popups in WPF application

Tags:

wpf

popup

WPF has the Popup class with which you can open a (small) window inside another window. This is used for example for Tooltips or ComboBoxes.

I need to find all of these popups which are currently opened inside a WPF window, so I can close them.

like image 946
HerrLoesch Avatar asked Jan 23 '13 11:01

HerrLoesch


1 Answers

If someone still need:

  public static IEnumerable<Popup> GetOpenPopups()
  {
      return PresentationSource.CurrentSources.OfType<HwndSource>()
          .Select(h => h.RootVisual)
          .OfType<FrameworkElement>()
          .Select(f => f.Parent)
          .OfType<Popup>()
          .Where(p => p.IsOpen);
  }
like image 141
xmetropol Avatar answered Sep 29 '22 03:09

xmetropol