升级到 .NET 4.0 后 WPF DataGrid 中的错误

发布于 2024-09-24 14:58:39 字数 1338 浏览 1 评论 0原文

情况如下:
DataGrid 有一个 RowDetailsTemplate,其中包含另一个 DataGrid(子网格)。如果添加包含 EventHandler 的 DataGridTemplateColumn,PresentationFramework.dll 将引发 NullReferenceException

此问题仅存在于 .NET 4.0 中。如果项目面向 .NET 3.5(并使用 WPFToolkit 作为 DataGrid 组件),则一切都会按预期运行。

我附上了一个重现此错误的小示例项目。项目中有一个自述文件,它再次解释了问题并显示了异常的堆栈跟踪。 (示例项目可以在此处找到)

重现步骤:
1. 按原样运行示例项目。
2. 尝试网格第一行中的“删除我”链接,确认它显示一条消息。
3. 单击第一列中的“显示”单元格,并确认它显示包含一个项目的子网格。
4. 尝试子网格中的“删除我”链接,确认它没有执行任何操作。(它未在代码中连接)。
5. 关闭窗口并转到MainWindow.xaml
6. 在 MainWindow.xaml 第 36 行连接 Hyperlink.Click 事件:将 Click="HyperlinkClick" 添加到 Hyperlink 标记。
7. 再次运行项目,点击第一列的“SHOW”:抛出NullReferenceException!

这是从 https://connect.microsoft.com/VisualStudio/feedback/details/603333/wpf-datagrid-rowdetails-add-2nd-datagrid-to-rowdetailstemplate-with-eventhandlers#details,但这对我来说是一个阻碍问题。

所以问题是:为什么会发生这种情况?我认为这是PresentationFramework 代码中的一个错误,但我不能100% 确定。我该怎么做才能使 EventHandler 按预期工作?

我找到了一个临时解决方法,允许用户按删除键,但这会破坏我们应用程序的行为。
有没有人可以重现并评论这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2024-10-01 14:58:39

我有一个类似的问题,似乎与 CanUserAddRows="True" 有关...如果我将其设置为 false,问题就会消失。

I had a similar problem that seemed to have something to do with CanUserAddRows="True"...if I set that to false the problem goes away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文