In a Windows 10 Universal application, I want to display a MessageDialog when I click the back button.
My page code is as follows:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
SystemNavigationManager.GetForCurrentView().BackRequested += GamePage_BackRequested;
}
private async void GamePage_BackRequested(object sender, BackRequestedEventArgs e)
{
var dialog = new Windows.UI.Popups.MessageDialog("Are you sure ?");
dialog.Commands.Add(new Windows.UI.Popups.UICommand("Yes"));
dialog.Commands.Add(new Windows.UI.Popups.UICommand("No"));
var result = await dialog.ShowAsync();
}
When I use the application in the "local machine", the dialog is well displayed. But when I turn Windows into “tablet mode”, or when I try to use it on my Windows phone, the ShowAsync method causes the application to crash (no errors).
Why is the application crashing?
source
share