Issue
I have the following form created with Xamarin Forms. I have drawn in a red rectangle to highlight the problem area. I need the blue color in the header to be a different color and show a title.
Here is what I am trying to approximate. Please ignore the back arrow and the fact the hamburger menu is on the right (btw, can a MasterDetail have the hamburger on the right vs. left?).
The following code is what I am using to create this. I am embedding my MainPage (which has the ListView) in a NavigationPage. Then I set the Detail page of a MasterDetailPage to the aforementioned NavigationPage. Setting the BackgroundColor property here isn't working. Notice the Title property isn't working either.
How can I change the color and title of the header's background?
var navPage = new NavigationPage(new MainPage());
App.Current.MainPage = new MasterDetailPage
{
BackgroundColor = Color.FromHex("#174873"),
Title = "MY DRIVES",
Master = new MenuPage()
{
Title = "Master Page Title"
},
Detail = navPage
};
Solution
Set the BarBackgroundColor
of the NavigationPage
. You can do something like this (in the most basic example sense):
var nav = new NavigationPage
{
Title = "Detail"
};
nav.PushAsync(new ContentPage() { Title = "Home" });
nav.BarBackgroundColor = Color.MediumPurple;
var mdp = new MasterDetailPage()
{
Master = new ContentPage()
{
Title = "Master"
},
Detail = nav
};
MainPage = mdp;
The title of the ContentPage
being presented by the NavigationPage
is what will show the title on that bar.
Answered By - Paul
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.