ContentControl in MainRegion

Mar 25, 2009 at 2:29 PM

Hi,
at the moment i have a hard wired menu on my Shell.xaml.
The region is defiend like here:
 <ContentControl Name="myContent"  Grid.Row="2" Grid.Column="1" cal:RegionManager.RegionName="MainRegion"/>

This menu loads moduls on demand with:
 
case

"Projecte":
{
this.moduleManager.LoadModule("ProjectsModule");
break;
}

the view is added via

regionManager.RegisterViewWithRegion("MainRegion", typeof(ProjectsView));

in the Initialze method of the module.

When i load a second module, the region is cleared and the second view is add.

If the first module is called again, nothing happends. Clearly while the view is added on module loadtime....

Is there any chance to switch the view's. So to say. the user loads and works with projectsmodule, switches to some other modeule and like to go back to the projects module.

Thanks
Peter

 

 

Mar 26, 2009 at 8:32 PM
Edited Mar 26, 2009 at 8:51 PM

Hi Peter,

 

The problem you are experiencing is because the Initialize method from the modules is called only once (if you call LoadModule on a module that is already loaded nothing should happen). So instead of just initializing the module you should also activate the view you want to be shown.

 

One way to achieve this and still keep modules decoupled might be using Event Aggregation. Your menu can publish an event that each module can subscribe to and active their corresponding view in response. For more information about using the EventAggregator, you can check the following topics from the documentation:

·         Communication 

·         Event Aggregation QuickStart

·         How to: Create and Publish Events

·         How to: Subscribe and Unsubscribe to Events

 

For more information about this, you might find useful the following discussions in the forum that are related to building menus and loading modules:

·         How to load a Module on Menu Click

·         Menu in a module

·         Accessing a shared Menu in Application Shell

·         Event subscribers? Views versus Regions?

·         How to activate a module after its initialize method has been executed?

·         Same module multiple times as TabItems

 

Hope it helps!

 

Matias Bonaventura

http://blogs.southworks.net/matiasb

Mar 31, 2009 at 6:33 AM

Thank you Matias

Peter