Setting BackButtonBehavior IsEnabled to False on view that is pushed onto the detail view of a MasterDetail windows behaves differently on Android and iOS. Android displays the back button but tapping it does nothing. iOS displays the back button and tapping it goes back.
In Forms setting Navigation.SetHasBackButton(false) would not over-ride the hamburger / open master behavior of the left toolbar item. I see no comparable way to do this with Shell. I do understand that I could create my own Hamburger icon and code the command, but in the very least there should be a way to set the icon to the default hamburger icon used in the MasterDetail page.
The objective is that the Master/Detail navigation would look and behave exactly the same regardless of how many items are in the navigation stack of the detail window.
<Shell.BackButtonBehavior >
<BackButtonBehavior IsEnabled="False" />
</Shell.BackButtonBehavior>
In keeping with Forms, I would expect to see the hamburger icon and tapping on it would open the Master view of the Master/detail page.
If the intention is really to disable the left toolbar item entirely, then the icon and text should not be displayed, or at least there should be an option to turn them off such as IsVisible.
Android displays the back button but tapping it does nothing.
iOS displays the back button and tapping it goes back.
Looking at this issue, if we do this:
async void PushPage(object obj)
{
var page = new ContentPage();
Shell.SetBackButtonBehavior(page, new BackButtonBehavior
{
IsEnabled = false,
Command = new Command(() => {
DisplayAlert("Clicked back", "You can't go back", "ok");
})
});
await Navigation.PushAsync(page);
}
One would expect the same behaviour on iOS and Android, right now iOS if we click back it doesn't run the command and it also doesn't disable the "back" behavior
When IsEnabled="False", the back button at the top navigation bar on Android behaves as expected i.e. the previous page is not displayed when it is pressed but when the software back button of phone is pressed, the previous page is displayed.
Is it possible to apply back button behaviour to hardware/software operating system buttons in Android and also the back gesture in iOS?
Heya, I have also noticed some inconsistencies when Back Button is pushed on a modal page. When navigation to the page is done using this method call. I am using Xamarin forms v 4.4.0 Application.Current.MainPage.Navigation.PushModalAsync()
For me Xamarin Forms seem to behave as follows:
On Android: Pushing the software back button down the bottom takes user to the last page.
On iOS: Back gesture does not take the user to the last page.
Expected behaviour is to take the user to the last page unless otheriwse configured.
Will appreciate if we have a look at this too please?
Hey @samhouts , would this issue be a good fit for a/backbutton label?
Most helpful comment
Hey @samhouts , would this issue be a good fit for a/backbutton label?