我在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>
当我编译代码时,会出现以下错误:
“UserControl1”的 ControlTemplate TargetType 与模板类型“UserControl”不匹配。
但是,当我调试应用程序时,它可以正常工作。
这个错误是什么意思?如何解决它?