C# Silverlight - When do Resource Dictionaries get created?

隐身守侯 提交于 2019-12-11 07:33:46

问题


I am working on a Silverlight 4 project where I get a memory leak because every time some xaml views are loaded they create their own instance of a class that then gets hooked with event triggers and don't get garbage collected. Removing the event listeners has proved too tricky under the circumstances for me to handle it that way. So Instead I want the instance of the class to be re-used every time the xaml view loads.

To do this I was planning on adding a Resource Dictionary to each project that this error is occurring in. My concern though is that I don't know when this Resource Dictionary will be created. When the solution first loads will it load the project then the resource dictionary, immediately creating the class for use? Or will it wait until something asks for it and then create it. Will what actually happens create a copy of the class that gets re-used by everyone that accesses it(as in not another copy)?

I also realize I can place the resources in app.xaml but I need to add many such classes and it will really clutter up the area which shouldn't be bothered with this problem.


回答1:


Use Christian Moser's SharedResourceDictionary to avoid loading second copies of the dictionary itself or anything it contains. This has saved us a long amount of load time in many controls.



来源:https://stackoverflow.com/questions/6751689/c-sharp-silverlight-when-do-resource-dictionaries-get-created

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