Oct 15, 2010 at 3:14 PM
Edited Oct 15, 2010 at 3:14 PM
Assuming that these views could be placed in different modules, a possibility for implementing what you’re explaining would be to have a
SingleActiveRegion (for example, a ContentControl) named “MainRegion” in which the views could be inserted, and have the buttons in the toolbar switch between views by publishing an event through the
Event Aggregator. If both views were located in the same module, it wouldn’t be necessary to use the Event Aggregator and you could switch between views directly from your ViewModel.
To this purpose, the
View Injection approach should be used, and the views should be registered with a name, like this:
When switching, each view would publish a “SwitchViewEvent” with the other view’s name as a parameter, to indicate that it should be activated.
For example, the code in your button for replacing the List View for the Edit View could be like this (assuming that myListView is a reference to your current view):
and the code in your Edit View for subscribing to that event could be like this:
private void addViewtoRegion(string viewName)
var view = regionManager.Regions["MainRegion"].GetView(viewName);
Since the SingleActiveRegion can only hold one active region at a time, activating the EditView will deactivate the ListView and vice-versa.
You can find more information about this in the UI Composition Quickstart (there is only a Silverlight version, but it could be useful anyway).
Hope this helps.