I came here to complement the answer by J-Trana.
He really got me curious for the Prism and I'm glad he did. This just rocks.
I've spent the last few weeks reading about it, watching the docs and the quickstart examples that come with it. These were my main references.
So, about the solution...
Prism Regions was indeed what I wanted. The Switchboard provided by him was key in my implementation but I tweaked it a little.
First I passed the UnityContainer inside it, so I could get more flexibility. (Or so I think it gives me.)
Second, I've created a method LoadModule (because I have a modular structure) like this.
public void LoadModule(string module) {
IModuleManager moduleManager = m_UnityContainer.Resolve();
moduleManager.LoadModule(module);
}
From what I got, when this LoadModule executes the Initialize()
method of a my modules, which are something like this...
public void Initialize()
{
Switchboard switchboard = Switchboard.GetSwitchboard();
IUnityContainer container = switchboard.GetCatalog();
switchboard.LoadView(RegionNames.ShellMainRegion, container.Resolve<HelloWorldView>());
}
And this works!
Some tips worth of note:
- `//The property that provides context(ViewModel) to the view.
[Dependency]
public HelloWorldViewModel HelloWorldViewModel
{
set
{
this.DataContext = value;
}
}
- That connects a ViewModel to a View as a property on the Views' code behind.
- this.Container.RegisterType();
- I register my modules this way:
` Type HelloWorldType = typeof(HelloWorldModule);
this.ModuleCatalog.AddModule(new ModuleInfo()
{
ModuleName = ModuleNames.HelloWorldModule,
ModuleType = HelloWorldType.AssemblyQualifiedName,
InitializationMode = InitializationMode.OnDemand
}); `
- And my switchboard is on my infrastructure module. The View creation is shoot up to the module that has it and this solved my problem.
I hope this isn't too confusing, and I really would like some comments on how I'm doing this stuff... Am I doing this the "right" way? Is there a more elegant way?
Stuff Like that...
Anyway, I hope this helps and motivates people that are trying to learn prism.
PS: How does this code tag work? And can I change the tags? mvvm-light makes no sense anymore.
DataTemplateSelector
: stackoverflow.com/questions/5309099/…. Also my solution can be applied to Silverlight after a few changes. – vortexwolf