MVVM Light screen activation - what is the recommended pattern?
By "screen activation" I mean a concept from Caliburn Micro, when you want either display something in the region that was not occupied or switch one view with another. In Caliburn Micro, all this is done from ViewModel's method by instantiating and activating another ViewModel. It seems to me that in MVVM Light, considering its "View First" approa开发者_如何学JAVAch, to achieve the same you need to use a code behind and just switch the content of a view host with some other view.
I was wondering if this can be done without code-behind and if there is a dominating pattern for this task.
In this post I outline the approaches usually taken to display dialogs from a MVVM Light view model.
MVVM Light does not have the concept of regions, neither does it force you to use one specific paradigm to solve a problem. This leaves you a lot of freedom, however, on the opposite this also means that you have to do more yourself.
If you need regions and plug-ins maybe using a larger framwork - like Prism, Caliburn, or Ocean (partially) - may be a better choice. If you are bound to MVVM Light and need this functionality you will have to create it yourself - hence the "light" part in the Name :-)
Edit
Your (Sergey's) comment got me thinking, so I went out and looked around and found something that migt fit your need.
Mike Hamilton implemented a conductor/screen logic based on MVVM Light. The samples do not use a ViewModelLocator
but I can see no reason why this couldn't changed (haven't tried it though - time permitting). However, the approach looks promising. Note: It may be applicable to WPF only - samples are WPF only and there is no navigation in it.
Bedides in source code the package is also available as a NuGet package.
Even if you want to roll your own implementation, the samples, source code and blog post give you a good starting point.
If you are targeting WP7 both Laurent Buginion and Jesse Liberty showed how to implement a NavigationService
- which also fits into this category.
As Silverlight and WP7 share quite a lot of commonality the NavigationService
approach can be transformed to work with Silverlight as well - actually I done this in a SL application I wrote.
Jay Kimble provides a template that implements yet another approach for Silverlight.
As to what is the "dominating" pattern I'd say for Siverlight/WP 7 it is the NavigationService
pattern, for WPF - ther really is no "dominating" pattern, however, some contenders (one shown).
精彩评论