简体   繁体   English

.NET 4.0中WPF Datagrid的怪异行为

[英]Weird behaviour of WPF Datagrid in .Net 4.0

Problem description: I have a small WPF window using Datagrid bound to an observable collection. 问题描述:我有一个使用Datagrid绑定到可观察集合的WPF小窗口。 When this window is launched in Windows OS having .net 4.5 then it works fine, but when I run in an OS where I have installed only .Net 4.0 (Example: Windows Server 2008R2) then this window crashes with the following exception. 在具有.net 4.5的Windows操作系统中启动此窗口时,它可以正常工作,但是当我在仅安装.Net 4.0的OS中运行(例如:Windows Server 2008R2)时,此窗口将崩溃,但以下情况除外。

例外

Or here: http://i.imgur.com/AxG9t5p.png 或者在这里: http : //i.imgur.com/AxG9t5p.png

The same window works fine if I install .net 4.5 even though my application is based on .net 4.0 and I am not using any feature specific to .net 4.5. 即使我的应用程序基于.net 4.0并且我没有使用任何特定于.net 4.5的功能,即使安装.net 4.5,该窗口也可以正常工作。

It would be great if someone could explain why different behaviour ? 如果有人可以解释为什么会有不同的行为,那就太好了!

Project can be found here: http://1drv.ms/1k9Yolx Thanks 项目可以在这里找到: http : //1drv.ms/1k9Yolx谢谢

I've tried to run your project at .Net4.5 and .Net 4.0 and I've not met any errors. 我尝试在.Net4.5和.Net 4.0上运行您的项目,但没有遇到任何错误。

You've caught ArgumentOutOfRangeException and this Exception is not related with platform .Net4.0 and .Net 4.5. 您已经捕获到ArgumentOutOfRangeException,并且此异常与.Net4.0和.Net 4.5平台无关。 Moreover, there is ArgumentOutOfRangeException in both .Net4.0 and .Net 4.5. 此外,.Net4.0和.Net 4.5中都存在ArgumentOutOfRangeException。

The code var t = Projects.ColumnFromDisplayIndex(2) gets the DataGridColumn at the specified index. 代码var t = Projects.ColumnFromDisplayIndex(2)获取指定索引处的DataGridColumn。 As you have 9 Columns(_name, ..., _path), you do nit catch any exception. 由于您有9列(_name,...,_ path),因此您确实可以捕获任何异常。 However, if you set to 10 like this Projects.ColumnFromDisplayIndex(10) , you will catch an ArgumentOutOfRangeException as you are out of range(you have 9 columns, but you try to get no existed column ). 但是,如果像这样Projects.ColumnFromDisplayIndex(10)那样设置为10,则超出范围时将捕获ArgumentOutOfRangeException (您有9列,但尝试获取不存在的列)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM