问题
I cannot figure out how to hide the Navigation bar when setting my applications main page to a "master-detail" page. If the master-detail page is NOT the main page of the application then the navigation bar hides correctly, but no matter what I do I cannot hide the nav bar if it is the main page.
I have tried the following in the constructor of the master page, the detail page and in the overridden OnAppearing method of both but the nav bar never hides.
NavigationPage.SetHasNavigationBar( this, false ); NavigationPage.SetHasBackButton( this, false );
I have also tried similar logic directly in the XAML but it never hides. If I first set my MainPage to another page then just navigate forward to the master-detail page the nav bar hides correctly.
Any thoughts/ideas?
回答1:
For the android implementation, add the following to your MainActivity.cs:
global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
For iOS, the process requires a custom renderer, but it's really basic:
public class iOSCustomMobilePageRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated) {
base.ViewWillAppear(animated);
if (ViewController != null && ViewController.ParentViewController != null && ViewController.ParentViewController.NavigationController != null) {
if (ViewController.ParentViewController.NavigationController.NavigationBar != null)
ViewController.ParentViewController.NavigationController.SetNavigationBarHidden(true, false);
}
}
}
来源:https://stackoverflow.com/questions/40873545/xamarin-forms-master-detail-page-main-page-hide-navigation-bar