我已经在WPF中创建了一个自定义ContentControl,并应用了以下模板:
<Style TargetType="{x:Type local:BdlUserControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:BdlUserControl">
<Grid x:Name="ContentGrid">
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="White">
<StackPanel HorizontalAlignment="Right">
<Button Content="Close" Width="50" Name="BtClose" Click="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BtClose_Click}"/>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<ContentPresenter Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
问题在于BtClose没有调用自定义控件代码后端中声明的BtClose_Click方法,如下所示:
public void BtClose_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("Test");
}
错误非常泛化:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
有什么线索可以解释这是为什么吗?