Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms - Getting Rid of Back Button In Nav Bar

Lets say the first page in the app is the login page and then it takes me to do the main menu screen, is there a way to get rid of the back button in the main menu navigation bar, like get rid of the login page stack?

thank you

like image 534
user3841879 Avatar asked Jul 24 '14 14:07

user3841879


3 Answers

In Xamarin.Forms 1.3 and greater you can use

NavigationPage.SetHasBackButton(this, false);

In Xaml you can add:

<ContentPage ....NameSpaces etc....
    NavigationPage.HasBackButton="False"
    Title="MyPage">
</ContentPage>
like image 79
User1 Avatar answered Oct 30 '22 06:10

User1


You can avoid having the Back button if you replace the Navigation.PushAsync(page) to Navigation.PushModalAsync(page) in your login page's code. Post some code if this somehow doesn't apply

This has to do with how navigation works in the underlying OS (at least in iOS that's the case) - there is a Navigation Controller which serves for pages to transition between each other and have a trace of previous screen so the user can go back.

like image 45
Sten Petrov Avatar answered Oct 30 '22 05:10

Sten Petrov


There are 2 ways to get rid of back button:
1) You can remove navigation bar from Xaml using Xamarin.Forms using below code

NavigationPage.SetHasNavigationBar (this, false);

Where this stands for current page / form instance.

2) Follow below mentioned steps

  • Navigate to login page when the app is loaded with Normal ContentPage instance of Login Page
  • Navigate to Main page from Login page using PushModalAsync and provide the main page instance as NavigationPage
  • And then from all the other pages, you can use PushAsync and it'll let you navigate to all the pages without any error.

Hope this helps!

like image 9
Nirav Mehta Avatar answered Oct 30 '22 06:10

Nirav Mehta