dotnet maui how to hide the back button on desktop?

Viewed 238

I'm trying to hide the backbutton shown in the image on desktop, but no matter what I tried, then it keept showing up.

I have tried

<Shell.BackButtonBehavior>
    <BackButtonBehavior IsVisible="False" IsEnabled="False" />
</Shell.BackButtonBehavior>

And I have tried following this SO post Why Back Button is hidden in Maui?

My navigation is done by saying await Shell.Current.GoToAsync(new ShellNavigationState(location), false);

Am I missing something?

enter image description here

2 Answers

This technique (the code in your question), added within the <ContentPage ... > declaration at the top of the xaml:

<Shell.BackButtonBehavior>
    <BackButtonBehavior IsVisible="False" IsEnabled="False" />
</Shell.BackButtonBehavior>

seems to work when using the Shell to activate pages in C# codebehind (often in the BindingSource e.g., viewmodel):

await Shell.Current.GoToAsync($"{nameof(MyContentPage)}");

Adding this within the <ContentPage ...> declaration at the top of the xaml:

NavigationPage.HasBackButton="false"

seems to be applicable when using the push/pop within a NavigationPage:

await Navigation.PushAsync(new DetailsPage());

I don't use the Navigation.PushAsync. My app requires very specific navigation based on current data state, so a stack doesn't work for me. I have verified setting the Shell.BackButtonBehavior (in the very code you provided) works in my case because I am activating pages via

await Shell.Current.GoToAsync
Related