在WPF应用程序中查找所有打开的弹出窗口 [英] Find all opened Popups in WPF application
本文介绍了在WPF应用程序中查找所有打开的弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
我需要找到所有这些当前在WPF窗口中打开的弹出窗口,因此我可以将其关闭.
I need to find all of these popups which are currently opened inside a WPF window, so I can close them.
推荐答案
如果仍然需要:
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);
}
这篇关于在WPF应用程序中查找所有打开的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文