I'm currently familiarizing myself with Prism 4.0 and MVVM (using Cinch 2.0 as the MVVM framework.) I'm building the shell for what will be an application with roughly 15 modules. We're using WPF.
The application uses a ribbon for its menu system. Modules are loaded when the user clicks on a button on the ribbon (the shell handles that task through its viewmodel.) The modules register their main view with the region manager (the shell defines only one main region, for now anyway.) Most modules are loaded on demand. This works fine in a simple scenario:
- User clicks on a button. Module gets loaded, view is added to the region and displayed.
- User clicks on a button for some other module. Same idea as above. The view for that module is displayed in the same region, replacing the view from the previous module.
Where things stop working is when the user then clicks again on the button for a previously loaded module. Since the module has already been loaded, pretty much nothing happens - the current view remains displayed on screen. That makes sense - LoadModule is pretty much ignored (or at least it looks like it is being ignored.)
I've done quite a few searches on Google for this, and most answers I found required the shell to navigate to the view. Now, unless I'm mistaken, this is coupling the shell to the modules a bit too much: The shell shouldn't know about the view(s) in any module. Essentially this seems to break the MVVM pattern. The shell knowing about the modules is a necessary coupling (in our case anyway - we don't (can't) use stuff like directory discovery. But the shell knowing about each module's views is pushing it, in my opinion.
Bottom line, the question is: How can I navigate between existing views, using a ribbon interface (well, the fact that it's a ribbon has no bearing on this) which is controlled by the shell, by having the shell "tell" an already-loaded module "hey, you've got focus again, so display whatever view was displayed the last time you were the star of the show."
Then again maybe I'm just going at this the wrong way... Wouldn't be a first. :)
Thanks!