PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 14, 2022

[FIXED] How to change NavBar colour of MasterMainPage in Xamarin

 September 14, 2022     background-color, cross-platform, navbar, xamarin.forms     No comments   

Issue

I'm building a Xamarin cross-platform App!

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

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!

https://i.stack.imgur.com/fbXie.png

https://i.stack.imgur.com/vuA1A.png


Solution

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.

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

NavigationPage.SetHasNavigationBar(this, false);

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

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

This will hide the NavigationBar of MasterDetailPage.



Answered By - MilanG
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing