Why does IViewAware.CacheViews influence IViewAware.GetView's behaviour?

Topics: Feature Requests, Framework Services
Jun 20, 2011 at 12:59 PM

I cannot see why CacheViews = false should alter GetView's behaviour. Was this intended?

I have a situation where I need CacheViews = false but I still want to access the view connected to a ViewModel.

Can this be done? It should be a quick fix  :)

Jun 20, 2011 at 2:07 PM

It's not as easy as you think....It's not possible in the current version. We hope to improve this in the future, but the verdict is still out on how to do it right.

Jun 20, 2011 at 2:11 PM

@pompomJuice: if you are interested in this topic, you can have a look at this old thread and write there your ideas, or comment about proposed solutions.

Jun 20, 2011 at 2:17 PM
Edited Jun 20, 2011 at 2:27 PM

Strange, I searched for CacheViews and I got nothing. [Edit] maybe not IViewAware

I will read it.

In my mind it goes like this: In the end there is a View with a ViewModel powering it, why is it so difficult for the ViewModel to know what view is displaying it? It should not be, surely? [Edit] And I know ViewModels should not fiddle with Views but sometimes this is unavoidable. With all these horribly coded Controls (such as telerik controls) you need to access the views unfortunately. 

Anyway, it seems like a heavy read. I will post if I have a suggestion or something.

Jun 20, 2011 at 2:46 PM

Set CacheViews = false, then override OnViewAttached or OnViewLoaded to grab the view yourself. GetView doesn't work because when CacheViews = false, the Screen does not hold a reference to the View. Thus, it cannot return it. In the future, we would like to have a way to separate the caching from the ability to get a view, but it's a bit difficult because of memory leak issues. Plus it would be a major breaking change to the API. That said, we'll get it done eventually.

Jun 20, 2011 at 3:01 PM

That sounds like a plan. Thanks.

This entire thing is becoming quite messy. Not only do we have to compensate for possible leaks inside the app, but inside CM or CM customizations and IoC as well. I am looking forward to an awesome solution, because this stuff is really draining me.


Oct 20, 2013 at 10:17 AM
Edited Oct 20, 2013 at 10:18 AM
We can solve this by using a WeakReference dictionary when CacheViews = false

E.g. something like this can be used:

So the behavior would not change and we don't leak memory and also easier than https://caliburnmicro.codeplex.com/discussions/240896.
Oct 29, 2013 at 5:48 AM