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

前端 未结 6 1621
死守一世寂寞
死守一世寂寞 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条回答
  •  萌比男神i
    2020-12-07 01:19

    The easiest, as @JordanMazurke also somewhat mentions, since the event for the back button cannot be handled currently (other than the physical back button for Android), is to either:

    1. NavigationPage.ShowHasBackButton(this, false)
    2. Pushing a Modal instead of a Page

    Then afterwards, you can add an ActionbarItem from where you can handle the Event.

    I personally spoke to the iOS team from Xamarin concerning this matter, and they basically told me we shouldn't expect support for handling the Event for the BackButtonPressed in the NavigationBar. The reason being, that on iOS, it's bad practice for the users to receive a message when Back is pressed.

提交回复
热议问题