Forum Xamarin.Forms

How to reference a StackLayout from a separate file to every ContentView's NavigationPage.TitleView

Hello Guys! I have question.

I am in a situation, where I need to have exactly the same Top Navigation Bar on every page except Page title. Can you suggest me how can I do it?

I want to do it, in separate Page. And then calling that page in every ContentView's NavigationPage.TitleView. But so far I couldn't figure it out.

This is my ContentView

`<NavigationPage.TitleView>
        <StackLayout BindableLayout.ItemsSource="{Binding BaseViewModel}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <datatemplate:PageTitleView />
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>
    </NavigationPage.TitleView>`

This is my Title Page Template. Which is PageTitleView

<?xml version="1.0" encoding="UTF-8" ?>
    <StackLayout
        x:Class="FSM.Views.DataTemplate.PageTitleView"
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:controls="clr-namespace:FSM.Controls"
        Margin="0,0,15,0"
        Padding="0"
        BackgroundColor="Red"
        HorizontalOptions="FillAndExpand"
        Orientation="Horizontal"
        Spacing="0"
        VerticalOptions="Center">
        <controls:CustomeButton
            Padding="0"
            BackgroundColor="Transparent"
            Clicked="GoBack"
            FontAttributes="Bold"
            FontSize="30"
            HeightRequest="30"
            HorizontalOptions="StartAndExpand"
            Text="&#xf060;"
            TextColor="#284b72"
            VerticalOptions="CenterAndExpand"
            WidthRequest="30">
            <controls:CustomeButton.FontFamily>
                <OnPlatform
                    x:TypeArguments="x:String"
                    Android="fontawesome-webfont.ttf#Font Awesome 4.7.0"
                    iOS="FontAwesome" />
            </controls:CustomeButton.FontFamily>
        </controls:CustomeButton>
        <Label
            FontAttributes="Bold"
            FontSize="20"
            HorizontalOptions="CenterAndExpand"
            Text="{Binding PageTitle}"
            TextColor="#284b72"
            VerticalOptions="Center" />
        <controls:CustomeButton
            Padding="0"
            BackgroundColor="Transparent"
            Clicked="Home_Clicked"
            FontAttributes="Bold"
            FontSize="30"
            HeightRequest="30"
            HorizontalOptions="EndAndExpand"
            Text="&#xf015;"
            TextColor="#284b72"
            VerticalOptions="CenterAndExpand"
            WidthRequest="30">
            <controls:CustomeButton.FontFamily>
                <OnPlatform
                    x:TypeArguments="x:String"
                    Android="fontawesome-webfont.ttf#Font Awesome 4.7.0"
                    iOS="FontAwesome" />
            </controls:CustomeButton.FontFamily>
        </controls:CustomeButton>
    </StackLayout>

Any kind of help will be much appreciated.

Sign In or Register to comment.