Reputation: 3067
I have a navigation view pattern in UWP app with a "navigation root" page hosting a frame for child pages. If I call a ContentDialog
from a child page, I can still access objects in the master page if I use keyboard shortcuts. This can easily result in an app crash if another content dialog is opened.
How can I make ContentDialog
truly modal?
Project demonstrating the issue can be found here: https://github.com/under3415/NavigationApp
In a nutshell, create two pages, one hosting the other in a frame
<Frame Grid.Row="1" x:Name="RootContentFrame"/>
In a master page, have a Button
or another object with AccessKey
defined.
In a child page, call a ContentDialog
. While content dialog is open press ALT
key and then the access key. Even though the modal dialog is open, the object behind fires.
Upvotes: 2
Views: 852
Reputation: 32775
In a master page, have a Button or another object with AccessKey defined. In a child page, call a ContentDialog. While content dialog is open press ALT key and then the access key. Even though the modal dialog is open, the object behind fires.
When the ContentDialog
show, it will block interactions with the app window until being explicitly dismissed. But it could not block access keys, because are keyboard shortcuts that improve the usability and the accessibility of your Windows applications by providing an intuitive way for users to quickly navigate and interact with an app's visible UI through a keyboard instead of a pointer device (such as touch or mouse).
For your scenario, we suggest make event to detect Dialog show or not then set root page IsEnable
true or false.
Make an Action in your app class
public static Action<bool> IsDialogOpen;
Detect Dialog open or close.
private async void Button_Click(object sender, RoutedEventArgs e)
{
ContentDialog dialog = new ContentDialog
{
Content = "Press ALT, then C or V",
Title = "Non Modal Dialog",
PrimaryButtonText = "OK"
};
dialog.Opened += Dialog_Opened;
dialog.Closed += Dialog_Closed;
_ = await dialog.ShowAsync();
}
private void Dialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
{
App.IsDialogOpen(false);
}
private void Dialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
App.IsDialogOpen(true);
}
Disable or Enable Root page base dialog open or not.
public NavigationRoot()
{
this.InitializeComponent();
App.IsDialogOpen = (s) =>
{
this.IsEnabled = s ? false : true;
};
}
Upvotes: 1