microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Ability to know whether a ContentDialog is displayed on the view for the current thread

Open jaigak opened this issue 4 years ago • 5 comments
trafficstars

Proposal: [Ability to know whether a ContentDialog is displayed on the view for the current thread

Today ContentDialog only allows one to be shown per thread however there's no way to know if a ContentDialog is already displayed other than trying to show another one and then catching the exception it throws when there's one already opened.

Summary

Add a method to know whether a ContentDialog is displayed on the current UI thread without the need to show a dialog and then catch exception if there's already one opened. Additionally a method to get the currently shown ContentDialog can be added.

Rationale

  • Make common tasks easier

Scope

Capability Priority
This proposal will allow developers to know whether a ContentDialog is displayed on the current UI thread Must

Important Notes

The API could look like this.

namespace Microsoft.UI.Xaml.Controls
{
    runtimeclass ContentDialog : Microsoft.UI.Xaml.Controls.ContentControl
    {
        static Boolean IsDialogShown(Microsoft.UI.Xaml.Window window);
        static Microsoft.UI.Xaml.Controls.ContentDialog GetCurrentlyShownDialog(Microsoft.UI.Xaml.Window window);
    }
}

This is for WinUI 3 but something similar could also be done for system XAML in the next version of Windows.

jaigak avatar Aug 23 '21 04:08 jaigak

It seems like this can already done by calling VisualTreeHelper.GetOpenPopups() and then checking if a ContentDialog is part of it instead of trying to show a new dialog and catch exception however it will be better if there was a method to check easily.

jaigak avatar Aug 23 '21 12:08 jaigak

Also it shouldn't be too hard to track which content dialogs your app has open, should it?

StephenLPeters avatar Sep 16 '21 22:09 StephenLPeters

@JaiganeshKumaran: Well that's not he same. You get via VisualTreeHelper.GetOpenPopupsForXamlRoot((Application.Current as App)?.Window.Content.XamlRoot)) only a visible Rectangle class. You did not get any hint for the displayed ContentDialog

SprengerS avatar Feb 20 '24 13:02 SprengerS

@SprengerS I do remember it working. Maybe it has been changed in WinUI 3 (I tested in WinUI 2 originally)?

jaigak avatar Feb 22 '24 05:02 jaigak

Sorry not really. Our project was migrated from UWP to WinUI3. So I only tested it on WinUi3

SprengerS avatar Feb 22 '24 06:02 SprengerS