views:

32

answers:

0

Situation is as follows:
A DataGrid has a RowDetailsTemplate, which contains another DataGrid (the subgrid). If you add a DataGridTemplateColumn which contains an EventHandler, a NullReferenceException is thrown by PresentationFramework.dll.

This issue is only present in .NET 4.0. If the project targets .NET 3.5 (and uses WPFToolkit for the DataGrid component), everything works as expected.

I attached a small sample project which reproduces this error. In the project is a README file which explain the issue again and shows the stacktrace of the exception. (the sample project can be found here)

Steps to reproduce:
1. Run the sample project as is.
2. Try the 'Delete Me' link in the first line of the grid, confirm that it displays a message.
3. Click the 'SHOW' cell in the first column, and confirm that it displays a subgrid with one item.
4. Try the 'Delete me' link in the subgrid, confirm that it does nothing.(it is not wired up in code).
5. Close the window and go to MainWindow.xaml
6. Wire up the Hyperlink.Click event in MainWindow.xaml on line 36: add Click="HyperlinkClick" to the Hyperlink tag.
7. Run the project again, and click on 'SHOW' in the first column: a NullReferenceException is thrown!

This is crossposted from https://connect.microsoft.com/VisualStudio/feedback/details/603333/wpf-datagrid-rowdetails-add-2nd-datagrid-to-rowdetailstemplate-with-eventhandlers#details , but this is a blocking issue for me.

So the problem is: why is this happening? I think this is a bug in the PresentationFramework code, but I'm not 100% sure. What can I do to make the EventHandler work as expected?

I found a temporary work-around by allowing the user to press the delete-key, but this breaks the behavior of our app.
Is there anyone who can reproduce and comment on this issue?