Xamarin.Forms ControlTemplate doesn't render Background

Viewed 152

I've got a ControlTemplate which does not display it's Background Color. I don't set anything in code or at other positions so I'm completly confused about this.

The ControlTemplate:

<ControlTemplate  ... >
<RelativeLayout BackgroundColor="Green">

    <Grid BackgroundColor="Black"
          RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=0}"
          RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=1,Constant=0}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ContentPresenter Grid.Row="1"
                          Grid.Column="1" 
                          BackgroundColor="Blue"/>

    </Grid>

</RelativeLayout>
</ControlTemplate>

And the View:

<ContentView ...
    ControlTemplate="{x:TemplateBinding templates:OverlayViewTemplate}">

<ContentView.Content>

    <Grid x:Name="GrdBase"
          BackgroundColor="White"
          VerticalOptions="Center"
          HorizontalOptions="Center">

        <Grid.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding ClickCommand}" />
        </Grid.GestureRecognizers>

        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="10" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
        </Grid.ColumnDefinitions>

        <StackLayout Grid.Row="0"
                     Grid.Column="0">
            <Label x:Name="LblTest"
                   Text="Hello Xamarin.Forms!" />
        </StackLayout>
    </Grid>

</ContentView.Content>
</ContentView>

Do I miss something here or is a Template unable to render a background color?

Edit

After a lot of testing around, I found out that the Template is not used by the ContentView. Even if I define the template inside my App.xaml and referencing it via ControlTemplate="{StaticResource ViewTemplate}". I have got an other Template which is used by my pages and this works with no issue, so is there a bug when using it with a View?

0 Answers
Related