Xamarin Forms Master Detail Page主页隐藏导航栏 [英] Xamarin Forms Master Detail Page Main Page Hide Navigation Bar

查看:136
本文介绍了Xamarin Forms Master Detail Page主页隐藏导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将应用程序主页设置为主从"页面时,我不知道如何隐藏导航栏.如果主从页面不是应用程序的主页,则导航栏会正确隐藏,但是无论我怎么做,如果它是主页,我都无法隐藏导航栏.

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.

我已经在母版页的构造器,详细信息页以及二者的重写的OnAppearing方法中尝试了以下内容,但导航栏从未隐藏.

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);

NavigationPage.SetHasNavigationBar( this, false ); NavigationPage.SetHasBackButton( this, false );

我也曾在XAML中直接尝试过类似的逻辑,但它从未隐藏.如果我先将MainPage设置为另一个页面,则只需向前导航至主从页面,导航栏即可正确隐藏.

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.

有什么想法/想法吗?

推荐答案

对于android实现,请将以下内容添加到您的MainActivity.cs中:

For the android implementation, add the following to your MainActivity.cs:

global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);

对于iOS,该过程需要自定义渲染器,但这确实很基本:

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);
        }
    }
}

这篇关于Xamarin Forms Master Detail Page主页隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆