Xamarin Forms Master Detail Page Main Page Hide Navigation Bar

元气小坏坏 提交于 2019-12-12 09:10:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!