简体   繁体   English

选择行时出现DataGrid错误

[英]DataGrid error when selecting a row

The following problem is not simple to explain. 以下问题不容易解释。 I have a Window which contains a DataGrid, and a ViewModel for the window. 我有一个包含DataGrid的窗口,以及该窗口的ViewModel。 The window.DataContext holds the ViewModel. window.DataContext包含ViewModel。 the DataGrid.ItemSource holds an ObservableCollection. DataGrid.ItemSource拥有一个ObservableCollection。 DataGrid's RowStyle's IsSelected Property is Binded to an IsSelected property in the PointData. DataGrid的RowStyle的IsSelected属性绑定到PointData中的IsSelected属性。

When I close the window and open a new one... and populate it with the old ViewModel data. 当我关闭窗口并打开一个新窗口时...并用旧的ViewModel数据填充它。 Selecting an "old" row throws an annoying Exception which says: "Collection was modified; enumeration operation may not execute" 选择一个“旧”行将引发一个令人讨厌的异常,该异常表明:“集合已修改;枚举操作可能无法执行”

If anyone has an idea of solving this situation I would truely appreaciate the help. 如果有人有解决这种情况的想法,我将不胜感激。 Thanks 谢谢

Normally this exception occurs when you modify a collection while using IEnumerable (an Enumerator) to loop through the collection. 通常,当您在使用IEnumerable(枚举器)循环浏览集合时修改集合时,会发生此异常。 The keyword foreach uses this interface. 关键字foreach使用此接口。

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

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