XAML - DataTemplate:抛出无法解释的异常(未处理的异常)

时间:2014-04-18 08:01:31

标签: wpf vb.net xaml datatemplate

2个数据表后的图片:

    <DataTemplate x:Key="templateGridDeleteBtn">
        <Button   Tag="{Binding stamnr}" Click="ButtonGridDelete_Click"   ToolTipService.ToolTip="Verwijderen aanvraag mutatie">
            <StackPanel  VerticalAlignment="Center" Orientation="Horizontal">
                <Image Source="../Images/DeleteRed.png" Width="20" Height="20" />

            </StackPanel>
        </Button>
    </DataTemplate>
    <DataTemplate x:Key="templateProcessRequest">
        <Button Tag="{Binding stamnr}" Click="ButtonProcess_Click" ToolTipService.ToolTip="Verwerken zonder de Wasserij te contacteren">
            <StackPanel  VerticalAlignment="Center" Orientation="Horizontal">
                <Image Source="../Images/Process.png" Width="20" Height="20" />

            </StackPanel>
        </Button>
    </DataTemplate>

Unhandled exception添加到Click-event时,我有一个templateProcessRequest。然而,它们背后的代码完全相同(见下文)

Private Sub ButtonGridDelete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
End Sub

Private Sub ButtonProcess_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
End Sub

如果我从第二个模板中删除Click-Event,则不会抛出异常。这种奇怪行为的原因是什么?

1 个答案:

答案 0 :(得分:0)

发现问题。它与XAML本身无关。由于inheritance引发了异常。 此控件充当多个其他文档的父级。如果参数的Click事件中显示的方法未出现在&#39; sub&#39; -controls中,则会抛出未处理的异常。

示例:

MainControl A
      => Has method ButtonProcess_Click

                   SubControl B inherits MainControl A
                   => Has method ButtonProcess_Click


                   SubControl C inherits MainControl A
                   => Doesn't Have method ButtonProcess_Click

将在SubControl C中抛出异常,但不会在A或B中抛出异常。