“Object reference not set to an instance of an object” in PresentationFramework with Live Shaping

纵然是瞬间 提交于 2019-12-01 05:43:29
Joe

Found a solution!

I was creating the view directly (rather than using the default view, because I in had two views driven from this collection:

KPIBarsView = new CollectionViewSource { Source = KPIBars }.View;

Which I did after reading this: http://social.technet.microsoft.com/wiki/contents/articles/26673.wpf-collectionview-tips.aspx

and the following SA questions:

However, I tried just creating a new collection, populating it with the same items and using:

KPIBarsView = CollectionViewSource.GetDefaultView(KPIBars);

solved the problem. Hope this is helpful for anyone else who stumbles upon it.

johnDisplayClass's comment is very helpful.

Something that worked for me: was if i also kept a member reference to each new CollectionViewSource as well as its CollectionView. This kept my live shaping and filtering working. Just this alone solved the same null ref that the OP was experiencing.

Another way to prevent this null exception is to set IsLiveSorting / IsLiveGrouping / IsLiveFiltering to false before the CollectionViewSource or CollectionView been garbage collected.

What I recommend is that you set yourself up to debug the Microsoft dll's from within your solution

https://msdn.microsoft.com/en-us/library/cc667410.aspx

Then make sure your debug settings have all of the possible exception types checked, then when you run your app again and break on the exception, you'll get a full stack trace that could help you work out the isse.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!