Share via


VisualTreeHelper.GetOpenPopups(Window) Method

Definition

Retrieves a collection of all open popup controls from the target Window.

public:
 static IVectorView<Popup ^> ^ GetOpenPopups(Window ^ window);
 static IVectorView<Popup> GetOpenPopups(Window const& window);
public static IReadOnlyList<Popup> GetOpenPopups(Window window);
function getOpenPopups(window)
Public Shared Function GetOpenPopups (window As Window) As IReadOnlyList(Of Popup)

Parameters

window
Window

The current Window instance to retrieve the popups from.

Returns

The list of all open popups. If no popups are open, the list is empty.

Remarks

Popups don't exist in the conventional XAML visual tree that begins from the root visual, although they are associated with the app main window. Unless your app maintains a list of all the Popup elements you've created as well as a status (the IsOpen value), it can be difficult to keep track of them. Sometimes you will want to clear all popups prior to initiating another UI action, like navigating the page or displaying a flyout. GetOpenPopups provides the utility so that you can get a reference to all these popups as Popup instances, and then you would typically set IsOpen to false on each of them.

Elements such as AppBar are not considered a popup, they are owned by the Page. A ToolTip is also not considered a popup, it's considered a child of the element that uses the ToolTipService attached properties to host it. Both AppBar and ToolTip elements are thus in the conventional XAML visual tree, even if they're not always displayed at the time. You could find these with GetChild or other VisualTreeHelperAPI, or by walking the tree with Child/Items/Children and related properties if you know the exact structure by type.

Applies to

See also