简体   繁体   中英

Windows Phone 8.1 override back button when message dialog is open

i have a message dialog which shows two button nav-to-page1 and nav-to-page2 button, means i have restrict user to either navigate to page1 or page2.

i am facing a problem in case when mesage dialog is open and back button is press this behaviour close my message dialog.

i can override back button in case when message dialog is not open. i want to overide back button when dialog is open.

MessageDialog dlg = new MessageDialog("Are you sure you want to quit you will loose all your work ?", "Warning");
dlg.Commands.Add(new UICommand("nav-to-page1", new UICommandInvokedHandler(CommandHandler1)));
dlg.Commands.Add(new UICommand("nav-to-page2", new UICommandInvokedHandler(CommandHandler1)));

await dlg.ShowAsync();

Any help would be greatly appreciated

Closing of messagedialog on Backkeypress is default. Dont think you can override this behavior as it does not hit backkeypress method when messagedialog is open. One suggestion: right now when you press back button it takes it as command and enters into "CommandHandler1" method. To avoid this while creating command, add some command id like

private async void gv_Tapped(object sender, TappedRoutedEventArgs e)
    {
        GridView gvi = sender as GridView;
        MessageDialog dlg = new MessageDialog("Are you sure you want to quit you will loose all your work ?", "Warning");
        dlg.Commands.Add(new UICommand("nav-to-page1", new UICommandInvokedHandler(CommandHandler1), 0));
        dlg.Commands.Add(new UICommand("nav-to-page2", new UICommandInvokedHandler(CommandHandler1),1));

        await dlg.ShowAsync();
    }



    private void CommandHandler1(IUICommand command)
    {
       // throw new NotImplementedException();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM