Xamarin.Forms ControlTemplate не отображает фон

У меня есть ControlTemplate который не отображает это Background Цвет. Я ничего не устанавливаю в коде или в других позициях, поэтому я полностью запутался в этом.

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>

И вид:

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

Я что-то здесь пропускаю или шаблон не может отобразить цвет фона?

редактировать

После многих испытаний я обнаружил, что Шаблон не используется ContentView, Даже если я определю шаблон внутри моего App.xaml и ссылки на него через ControlTemplate="{StaticResource ViewTemplate}", У меня есть другой шаблон, который используется моими страницами, и это работает без проблем, поэтому есть ли ошибка при использовании его с View?

0 ответов

Другие вопросы по тегам