Extending Erwin van der Valk's extensions

Topics: Prism v2 - WPF 3.5, Prism v2 - WPF 4
Sep 16, 2010 at 11:42 AM

Hi

 

I'm wondering if anyone here are using Erwin van der Valk's prism extensions (http://blogs.msdn.com/b/erwinvandervalk/archive/2009/03/02/how-to-build-an-outlook-style-application.aspx) for creating Outlook style applications? It seems Erwin is not responding to comments to the blog post anymore, so my hope is that someone in this forum is able to help.

Now, while I am not using all of the ideas he has come up with, I especially like the idea he has about doing viewmodel first development. His design implies that you bind viewmodels to regions, instead of the normal Prism approach of binding views to regions, and this is where my problem lies.

Normally you can tell Prism to use the same instance of a view with a certain region, but with Erwin's code, you register the viewmodel with a region:

RegionManager.RegisterViewWithRegion("MyRegionName", () => myViewModel) // Specific vm instance

RegionManager.RegisterViewWithRegion("MyRegionName", typeof(MyViewModel)) // New vm instance each time the region is activated

We use the concept keeping instance of a viewmodel a lot, so that we don't have to re-intialize the vm each time, and restore its state.

However, we sometimes also need to remember the view's state, so that e.g. when the user switches back and forth between tabs, the application remembers list selections, un-commited text box entries etc.

Is there a way of also caching the view along with the viewmodel? E.g. would it be possible to cache the entire VisualizingRegion from Erwin's concept, instead of just the viewmodel. Or is there a an entirely different approach I should consider instead.



 

I hope someone is able to point me in the right direction

Sep 17, 2010 at 6:53 PM

Hi lillebak,

I have not used Erwin’s extensions, but most prism Quickstarts store the V and VM state until they are explicitly removed from their regions.

In general, each VM is associated with a V, whether you use a viewmodel first or a view first approach. This is how prism regions work, as views are not disposed until they are removed from the regions.

So, a possible approach might be to add a reference to your view in your viewmodel. Therefore, as long as your VM keeps a reference to its V, the V will be kept alive.  

Please let me know if this helps.

Fernando Antivero
http://blogs.southworks.net/fantivero