VisualTreeHelper.GetOpenPopups(Window) VisualTreeHelper.GetOpenPopups(Window) VisualTreeHelper.GetOpenPopups(Window) 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 window) const;
public static IReadOnlyList<Popup> GetOpenPopups(Window window)
Public Shared Function GetOpenPopups(window As Window) As IReadOnlyList<Popup>(Of Popup)

Parameters

window
Window Window

The current Window instance to retrieve the popups from.

Returns

IReadOnlyList<Popup> IReadOnlyList<Popup>

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 VisualTreeHelper API, or by walking the tree with Child/Items/Children and related properties if you know the exact structure by type.

See also