WPF具有Popup类,您可以使用该类在另一个窗口中打开(小)窗口.这用于例如Tooltips或ComboBoxes.
我需要找到当前在WPF窗口中打开的所有弹出窗口,以便我可以关闭它们.
小智 14
如果有人仍然需要:
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);
}
Run Code Online (Sandbox Code Playgroud)