Windows 10 development: displaying a message box when a phone button is pressed

I want to display a message dialog box on a page when the back button is pressed on that page.

I already made the back button, as it should. Therefore, I do not include the full code that makes the back button work. I need the message box to appear on a specific page (in this case, SomePage).

I have this code in the App.xaml.csevent OnBackRequested:

if (rootFrame.CanGoBack && rootFrame.SourcePageType.Name != "SomePage")
{
    MessageDialog errormessage = new MessageDialog("Something");

    errormessage.Commands.Add(new UICommand("Some Option", new UICommandInvokedHandler(this.CommandInvokedHandler)));
    errormessage.ShowAsync();
}
private void _CommandInvokedHandler(IUICommand command)
{
    Frame aFrame = Window.Current.Content as Frame;

    if (command.Label == "Some Option")
    {
        aFrame.GoBack();
    }

}

System.ArgumentException ShowAsync(). , ShowAsync() App.xaml.cs, SomePage, , , SomePage. , .

+4

All Articles