C
C#4mo ago
Pandetthe

Find popup window in Wpf

Hi, I want to get all opened popups in a specific window in Wpf, but I couldn't find a solution to solve it.
3 Replies
Pandetthe
Pandetthe4mo ago
I found that in Uwp exists VisualTreeHelper.GetOpenPopups(), but is there any option to use it in Wpf?
br4kejet
br4kejet4mo ago
You could use reflection to access the Window._showingAsDialog field, then iterate it using Application.Current.Windows.Cast<Window>().Where(x => x.Parent == targetParenttWindow && IsOpenedAsDialog(x))
Pandetthe
Pandetthe4mo ago
It's not working for popups used for example in combobox I found solution
PresentationSource.CurrentSources.OfType<HwndSource>()
.Select(h => h.RootVisual)
.OfType<FrameworkElement>()
.Select(f => f.Parent)
.OfType<Popup>()
.Where(popup => popup.IsOpen);
PresentationSource.CurrentSources.OfType<HwndSource>()
.Select(h => h.RootVisual)
.OfType<FrameworkElement>()
.Select(f => f.Parent)
.OfType<Popup>()
.Where(popup => popup.IsOpen);