How to intercept Navigation Bar Back Button Clicked in Xamarin Forms?

前端 未结 6 1637
死守一世寂寞
死守一世寂寞 2020-12-07 00:41

I have a xamarin form page where a user can update some data in a form. I need to intercept the Navigation Bar Back Button Clicked to warn the user if some data have not bee

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 01:20

    This is an inherently difficult task and the only way I got around it was to remove the back button entirely and then handle the backwards navigation from a 'save' button.

    I have done a brief search of the Xamarin.Forms forum and the following has been suggested:

    public override bool OnOptionsItemSelected(Android.Views.IMenuItem item)
    {
        return false;
    }
    

    The link for the post is as follows:

    https://forums.xamarin.com/discussion/21631/is-there-nay-way-of-cancelling-the-back-button-event-from-the-navigationpage

提交回复
热议问题