Forum Xamarin.Forms

Why am I getting key already added error in App.Xaml when adding control template?

KyleWarrenKyleWarren USUniversity ✭✭
edited April 2017 in Xamarin.Forms

In my app.xaml I added a control template, and now I get an error when trying to compile ... System.ArgumentException: An item with the same key has already been added.

 <Style TargetType="Label">
    <Setter Property="FontSize" Value="{StaticResource BaseFontSize}"/>
    <Setter Property="TextColor" Value="{StaticResource BaseTextColor}"/>
</Style>
  <Style x:Key="PageStyle" TargetType="ContentPage">
      <Setter Property="BackgroundColor" Value="{ StaticResource PageDefaultBackgroundColor }" />
      <Setter Property="Padding" Value="{StaticResource GenericPagePadding}"/>
  </Style>

  <ControlTemplate x:Key="HeaderAndFooterTemplate">
    <AbsoluteLayout BackgroundColor="#272b2f" HeightRequest="60">
        <StackLayout AbsoluteLayout.LayoutBounds=".5,.5,1,.5" AbsoluteLayout.LayoutFlags="All"
            Orientation="Horizontal" HorizontalOptions="Center">
            <Label TextColor="White">Ic</Label>
            <Label TextColor="White" Margin="-2,0,0,0">Header</Label>
        </StackLayout>
        <Label AbsoluteLayout.LayoutBounds="1,.5,1,.5" AbsoluteLayout.LayoutFlags="All" 
               TextColor="White" HorizontalOptions="End" Margin="0,0,20,0">HA</Label>
    </AbsoluteLayout>
    <ContentPresenter/>
      <AbsoluteLayout BackgroundColor="#FFE70D30" AbsoluteLayout.LayoutBounds=".5,1,1,1" HeightRequest="60">
        <Label AbsoluteLayout.LayoutBounds=".5,.5,.5,.5" AbsoluteLayout.LayoutFlags="All" 
               TextColor="White">Create New</Label>
        <Label AbsoluteLayout.LayoutBounds="1,.5,1,.5" AbsoluteLayout.LayoutFlags="All" 
               TextColor="White" HorizontalOptions="End" Margin="0,0,20,0">+</Label>
    </AbsoluteLayout>
  </ControlTemplate>

And in my ContentPage I have:

<ContentView x:Name="contentView" ControlTemplate="{StaticResource HeaderAndFooterTemplate}></ContentView>
<Label>Test</Label>
Tagged:
Sign In or Register to comment.