Upgrade from .NET 4.0 to .NET 4.5 issue

There is a compatible issue found during upgrading from .net 4.0 to .net 4.5. The application crashed with following error:

This exception was thrown because the generator for control 'System.Windows.Controls.DataGrid Items.Count:5' with name '(unnamed)' has received sequence of CollectionChanged events that do not agree with the current state of the Items collection. The following differences were detected: Accumulated count 4 is different from actual count 5. [Accumulated count is (Count at last Reset + #Adds - #Removes since last Reset).]

The solution is enable cross thread collection synchronization:

BindingOperations.EnableCollectionSynchronization(Items, _syncLock);

 

参考链接:

http://stackoverflow.com/questions/14336750/upgrading-to-net-4-5-an-itemscontrol-is-inconsistent-with-its-items-source

 

posted @ 2017-03-21 10:03  liangzi4000  阅读(301)  评论(0编辑  收藏  举报