dotnet maui how to hide the back button on desktop?
Asked Answered
B

3

5

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

Bedesman answered 16/8, 2022 at 11:39 Comment(0)
C
15

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
Cody answered 15/9, 2022 at 1:10 Comment(1)
Correct spelling in answer.Leyes
M
4

So everything you need to know can be found here:

https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/navigationpage

NavigationPage.HasBackButton = true/false

Image (Proof) https://gyazo.com/afbc744e7b6c5d1caa56960a536390c7

If this was helpful, mark this please as answer :)

Mesial answered 16/8, 2022 at 12:40 Comment(1)
This is not working for me. What am I missing?? gyazo.com/315929b52422ddd1df95cb5b1edbde8eKantianism
T
0

To enable/disable something you can use OnPlatform or OnIdiom Exemple :

NavigationPage.HasBackButton="{OnIdiom Default='True', Desktop='False'}"
Taub answered 14/10, 2022 at 20:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.