amarin中更改MasterMainPage的NavBar颜色

amarin中更改MasterMainPage的NavBar颜色

本文介绍了如何在Xamarin中更改MasterMainPage的NavBar颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Xamarin跨平台应用程序!

I'm building a Xamarin cross-platform App!

问题是我想使用抽屉菜单更改MainPageMainPageNavigationBar颜色.

The problem is I want to change the colour of NavigationBar of MainPage which is MasterPage with a drawer menu in it.

我尝试使用此代码更改颜色,但在NavBar上出现了一个我不想要的额外条.

I tried with this code to change the colour but an extra bar appears on NavBar which I don't Want to.

App.xaml.cs:

  MainPage = new NavigationPage(new MainPage())

        {
            BarBackgroundColor = Color.FromHex("#00477f"),
            BarTextColor = Color.White,
        };

屏幕截图:这些屏幕截图显示了我面临的问题!

ScreenShots:These Screenshots shows what the problem I'm facing!

推荐答案

在这里,当您分配App.xamlMainPageNavigationPage时,它显示了它自己的NavigationBar.在引擎盖下,您的MasterDetailPage还显示了NavigationBar.因此,您正在查看两个NavigationBar.

Here, when you assign App.xaml's MainPage, a NavigationPage, it shows it's own NavigationBar. Under the hood, your MasterDetailPage also shows the NavigationBar. Thus, you are viewing two NavigationBars.

转到您的MainPage.xaml.cs后端页面,然后在构造函数中编写以下行:

Go to your MainPage.xaml.cs backend page and in the Constructor, write the line:

NavigationPage.SetHasNavigationBar(this, false);

因此,您的MainPage.xaml.cs应该如下所示:

Thus, your MainPage.xaml.cs should look like :

public MainPage()
{
    NavigationPage.SetHasNavigationBar(this, false);
    InitializeComponent();
    ......
}

这将隐藏MasterDetailPage的NavigationBar.

This will hide the NavigationBar of MasterDetailPage.

这篇关于如何在Xamarin中更改MasterMainPage的NavBar颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:24