Image following 2 datatemplates:

    <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>

I'm having an Unhandled exception when adding the Click-event to my templateProcessRequest. Yet the code behind them is exactly the same (see below)

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

If i remove the Click-Event from my second template then the exception isn't thrown. What is the reason of this strange behavior?

有帮助吗?

解决方案

Found the problem. It had nothing to do with the XAML itself. The exception was thrown due to inheritance. This control acts as parent for multiple other documents. And if the method shown in the Click event of the parameter isn't present in the 'sub'-controls then an unhandled exception is thrown.

Example:

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

An exception will be thrown in SubControl C but not in A or B.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top