microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
Ability to know whether a ContentDialog is displayed on the view for the current thread
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.
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.
Also it shouldn't be too hard to track which content dialogs your app has open, should it?
@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 I do remember it working. Maybe it has been changed in WinUI 3 (I tested in WinUI 2 originally)?
Sorry not really. Our project was migrated from UWP to WinUI3. So I only tested it on WinUi3