ControlTemplate TargetType does not match templated type

Viewed 3211

I have created this usercontrol in WPF

<UserControl x:Class="WpfApp1.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:WpfApp1"
         DataContext="{Binding RelativeSource={RelativeSource Self}}">
<UserControl.Template>
    <ControlTemplate TargetType="{x:Type local:UserControl1}">
        <Grid x:Name="LayoutRoot" Background="White" Margin="7,7,7,0">
        </Grid>
    </ControlTemplate>
</UserControl.Template>

When I compile this I get the following error.

'UserControl1' ControlTemplate TargetType does not match templated type 'UserControl'.

But when I debug the application it works fine.

What does this error mean? And how do I fix it?

1 Answers
Related