How to check if ANY ContentDialog is open?

ContentDialog is shown in the PopupRoot so using VisualTreeHelper.GetOpenPopups() will help you get it.

var openedpopups = VisualTreeHelper.GetOpenPopups(Window.Current);
foreach (var popup in openedpopups)
{
   if(popup.Child is ContentDialog)
   {
      //some content dialog is open.
   }
}

Tested accepted answer (by Vignesh) on target Windows 10 build 18362 and find that ContentDialog is never a child of popup. In my case simple check of the count works best:

    protected bool IsAnyContentDialogOpen()
    {
        return VisualTreeHelper.GetOpenPopups(Window.Current).Count > 0;
    }

Please feel free to comment if there's any problems with this approach. Thanks.

Tags:

C#

Uwp