user3841879
user3841879

Reputation: 659

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

Upvotes: 37

Views: 40200

Answers (4)

Nirav Mehta
Nirav Mehta

Reputation: 7073

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!

Upvotes: 9

JKennedy
JKennedy

Reputation: 18827

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>

Upvotes: 72

Duyen-Hoa
Duyen-Hoa

Reputation: 15804

By using CustomRenderer, you call this function in ViewWillAppear in your customized view controller

public override void ViewWillAppear (bool animated)
{
    base.ViewWillAppear (animated);
    this.ParentViewController.NavigationItem.SetHidesBackButton (true, false); 
    //remember to use ParentViewController to reference to the NavigationViewController (if your contentPage is direct under a navigation controller. I don't know why but Xamarin must have a bug with SetHidesBackButton. If you call with this.NavigationItem.SetHidesBackButton(...), it should not work. 
    ... other implements here ...
}

Upvotes: 4

Sten Petrov
Sten Petrov

Reputation: 11040

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.

Upvotes: 13

Related Questions