Can customize NavigationBar to my style?

YURNO 116 Reputation points
2021-06-21T11:19:57.43+00:00

Now, MainPage is TabbedPage.
TabbedPage have children is NavigationPage.
I want to customize NavigationBar to same every page by create CustomRenderer.
Is it possible?
The condition is that not use Shell.
Thanks for the answer in advance.

P.S. If you don't understand my question, I'm sorry. Because my English is not strong.
P.S. I use only C# to do that, not use XAML.

Current
107577-image.png

Target
107636-image.png

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
    2021-06-22T02:30:47.807+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    Is it possible if we just create it once and apply it to all pages?

    You can create a parent contentpage(e.g. CustomContentPage) and let the other pages inherit it.

    You can refer to the following code:

    CustomContentPage.xaml.cs

    [XamlCompilation(XamlCompilationOptions.Compile)]  
    public partial class CustomContentPage : ContentPage  
    {  
        public CustomContentPage()  
        {  
            InitializeComponent();  
        }  
    }  
    

    CustomContentPage.xaml

    <?xml version="1.0" encoding="utf-8" ?>  
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
                 x:Class="TabbedPageWithNavigationPage.CustomContentPage">  
      
        <NavigationPage.TitleView>  
            <StackLayout  Orientation="Horizontal">  
                <Image Source="star.png"   
                       WidthRequest="40"   
                       HeightRequest="40"  
                       VerticalOptions="CenterAndExpand"  
                   />  
      
                <Label   Text="test page"  HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>  
      
                <Image Source="gallary.png"   
                       WidthRequest="40" HeightRequest="40"  
                       VerticalOptions="CenterAndExpand"  
                    />  
            </StackLayout>  
        </NavigationPage.TitleView>  
    </ContentPage>  
    

    Make other pages inherit it, for example there is a SettingsPage page, we can do like this:

    public partial class SettingsPage : CustomContentPage  
    {  
    	public SettingsPage ()  
    	{  
    		InitializeComponent ();  
    	}  
    }  
    

    and SettingsPage.xaml :

    <?xml version="1.0" encoding="UTF-8"?>  
    <tabbedpagewithnavigationpage:CustomContentPage  xmlns:tabbedpagewithnavigationpage="clr-namespace:TabbedPageWithNavigationPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TabbedPageWithNavigationPage.SettingsPage" IconImageSource="settings.png" Title="Settings">  
    	<ContentPage.Content>  
    		<StackLayout>  
    			<Label Text="Settings go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />  
    		</StackLayout>  
    	</ContentPage.Content>  
    </tabbedpagewithnavigationpage:CustomContentPage>  
    

    Now the UI of page SettingsPage is:

    107916-image.png

    Best Regards,

    Jessie 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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Alessandro Caliaro 4,196 Reputation points
    2021-06-21T11:21:35.173+00:00
    1 person found this answer helpful.

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.