Forum Xamarin.Forms

Different Title Views in Tabbed Page

I have tabbed page in my application and i want to show different title for the each page in the navigation.titleviews. How can achieve this?

Best Answer

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 17

    You could customize a contentView ,createTitleProperty BindableProperty and create binding with the page's Title .

    Custom ContentView

    public class NavigationView : ContentView
    {
        public static readonly BindableProperty TitleProperty =
                                        BindableProperty.Create("Title",
                                            typeof(string),
                                            typeof(NavigationView),
                                            defaultValue: null,
                                            defaultBindingMode: BindingMode.OneWayToSource);
    
        public string Title
        {
            get => (string)GetValue(TitleProperty);
            set => SetValue(TitleProperty, value);
        }
    }
    

    XAML of Page

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        xmlns:local="clr-namespace:TitleView" 
        x:Class="TitleView.TitleViewPage"
        x:Name="_self"
        Title="{Binding Path=Content.Title, Source={x:Reference _self}}">
        <local:NavigationView Title="This is page-1">
            <Button Text="Go to page-2" Clicked="Handle_Clicked" />
        </local:NavigationView>
    </ContentPage>
    

    Detailed refer

    https://stackoverflow.com/questions/45834558/how-to-dynamically-change-the-navigation-bar-title-when-contentview-changes

    https://stackoverflow.com/questions/55161678/xamarin-navigation-bar-not-showing-titleview/55770906

  • EbubekirSezerEbubekirSezer Member ✭✭

    @ColeX It didnt work for me

  • Dinesh_OfficialDinesh_Official Member ✭✭✭

    @EbubekirSezer , Each ContentPage have a property called Title, you can assign the values for them.

    Can you please share some additional information? how you are defining pages in the tabbed page which might be helpful to share the thoughts

  • EbubekirSezerEbubekirSezer Member ✭✭

    @Dinesh_Official
    I have default tabbed page and i navigate to the tabbed page as a NavigationPage to have titleview. I added my child tabbed like in the below in the each tab i want to show different titleview, how can i achieve that?
    Children.Add(new Content1()); Children.Add(new Content2()); Children.Add(new Content3()); Children.Add(new Content4());

  • EbubekirSezerEbubekirSezer Member ✭✭

    @Dinesh_Official thanks i followed that logic and it worked

  • Dinesh_OfficialDinesh_Official Member ✭✭✭

    @EbubekirSezer , great :).

Sign In or Register to comment.