Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Navigation Page Stacks + Back Press override

$
0
0

I've been trying to override the back button on Windows Phone to show a dialog that asks the user whether they would like to proceed with moving "back" which logs them out, or cancel. I set the e.Cancel to true, but the app will pop the page off the stack REGARDLESS of the user's response. It appears that the Forms navigation stack will always try to pop a page off when back is pressed.

protected override void OnBackKeyPress(CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
            if (MessageBox.Show(Strings.logoutDialog, "Confirm Exit?", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
            {
                e.Cancel = true;
            }
            // Either response will cause the app to pop off the page.
        }

Originally my app had multiple content pages which I would set within the Main page and allows me to override and cancel the back button accordingly. The only issue was that my UI awaits such as the ActionSheet and Alert Dialogs would not await and would proceed regardless of user input. I was only able to get around the await issue by navigating in a nav stack instead.

Does anyone have any ideas on how to solve either of these problems? At the moment it looks like I can only have one of these issues solved at a time.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>