Change the second navigation bar text color different with main page color

Jason Tho 1 Reputation point
2021-02-07T07:39:33.43+00:00

Xamarin form with 2 pages. I wish change the second navigation bar text color different with main page.
the code at App.xaml.cs will set both page together. how to make this separately?

 MainPage = new NavigationPage(new EntryPage())            
            {                
                BarTextColor = Color.White               
            };
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,366 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,961 Reputation points
    2021-02-08T02:06:27.38+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Change the second navigation bar text color different with main page color

    Try using NavigationPage.TitleView to display the text content. You could define a different textColor in each page.

    Check the code:

       <ContentPage ...  
           x:Class="TestApplication_4.MainPage">  
         
           <NavigationPage.TitleView>  
               <StackLayout>  
                   <Label Text="MainPage" FontSize="18" TextColor="White"/>  
               </StackLayout>  
           </NavigationPage.TitleView>  
         
           ...  
       </ContentPage>  
         
       <ContentPage ...  
           x:Class="TestApplication_4.Page1">  
         
           <NavigationPage.TitleView>  
               <StackLayout>  
                   <Label Text="Page1" FontSize="18" TextColor="Red"/>  
               </StackLayout>  
           </NavigationPage.TitleView>  
           ...  
       </ContentPage>  
    

    Tutorial: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.