Forum Xamarin.Forms

Bind a property in a Control Template

arame3333arame3333 GBMember ✭✭

I want to put the page title in the Control Template.
This will have to be a bindable property as it will be different for each page.
I cannot get the binding to work.
I am using Prism which binds the View Model to the related page.
So each relevant ViewModel implements the IMainHeader interface;
public interface IMainHeader
{
string HeaderTitle { get; }
}

ViewModel implementing IMainHeader;

     public class ConfirmInspectorViewModel : BindableBase, INavigatedAware, IMainHeader
        {
            public string HeaderTitle => "Confirm Inspector";

App.XAML;

<?xml version="1.0" encoding="utf-8" ?>
<prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Sir.Mobile.App"
             xmlns:prism="clr-namespace:Prism.Unity;assembly=Prism.Unity.Forms">
    <prism:PrismApplication.Resources>
        <ResourceDictionary>
            <ControlTemplate x:Key="MainHeader">
                <StackLayout VerticalOptions="StartAndExpand">
                    <Label Text="{TemplateBinding Parent.HeaderTitle}"
                           TextColor="Black"
                           VerticalOptions="Center" />
                    <ContentPresenter></ContentPresenter>
                </StackLayout>
            </ControlTemplate>
        </ResourceDictionary>
    </prism:PrismApplication.Resources>
</prism:PrismApplication>

Answers

Sign In or Register to comment.