How to: Populate the Module Catalog from XAML in a WPF application using the Composite Application Guidance for WPF & Silverlight (Prism-v2)
August 9th, 2009
The other day I was trying to create a new WPF Prism application and I wanted to be able to load modules from XAML. To make things simpler I decided to check the documentation, but was not able to find any example on how to get this done, as the sample is for Silverlight applications. After this “revelation” I started my research on how this could be done. The most important question was what to put in the Ref attribute, which is where the module assembly is located.
First, and as it is done in the Silverlight approach, the GetModuleCatalog method of the UnityBootstrapper must be overriden with code similar to this:
protected override IModuleCatalog GetModuleCatalog() { return ModuleCatalog.CreateFromXaml( new Uri(“/ProjectName;component/ModulesCatalog.xaml”, UriKind.Relative)); }
It came to my mind that I had once answered a related question in the Prism forums, so I thought that would be a good place to start. As it is explained in the question, the Ref attribute must start “file://”, but what else should I add to this attribute?
It turns out the answer is quiet simple (fortunately). You simply have to make sure the module’s assembly is copied when built in the same folder as your Shell project is and since one of the module’s I wanted to load was called SearchModule, this is the XAML outcome:
<prism:ModuleInfo Ref=”file://SearchModule.dll” ModuleName=”SearchModule” ModuleType=”SearchModule.ModuleInit, SearchModule, Version=1.0.0.0″ InitializationMode=”WhenAvailable”> </prism:ModuleInfo>
The rest of the attributes remain the same as in the Silverlight approach.
I hope this is useful and saves you some trouble for you if you take this approach to load modules in your Prism WPF application.

August 9th, 2009 at 7:37 am
How to: Populate the Module Catalog from XAML in a WPF application using the Composite Application Guidance for WPF & Silverlight (Prism-v2)…
Thank you for submitting this cool story - Trackback from DotNetShoutout…
January 21st, 2010 at 4:26 pm
So I’m starting to use prism and I’m wondering what the advantages are loading from XAML instead of from a coded (and type safe) myCatalog.AddModule( typeof (Foo) ) in GetModuleCatalog.
Any ideas?
January 25th, 2010 at 10:03 am
Hi Stu,
The main advantage to using any other kind of module loading other than the in-code approach, is that there is no need to reference your module assemblies from your Shell. This allows you to decouple your Shell from your application modules and load different modules without the need to re-build the application, as you can just modify a configuration file.
You can take a look at the Modularity Quickstarts to see how this works. Take into account that there is no Modularity QS that shows how to load modules from XAML in WPF.
Please let me know if this helps.
Damian
January 27th, 2010 at 5:24 am
Thank you for that help, but I’m still having troubles in loading a xaml-catalog with WPF.
I’ve added a Catalog.xaml as Content to my project and if I do:
var uri = new Uri(”/Assembly;component/Catalog.xaml”, UriKind.Relative);
var foo = System.Windows.Application.GetResourceStream(uri);
foo is null. As well as the catalog when calling ModuleCatalog.CreateFromXaml(uri). It seems that the Catalog.xaml is found because if I change the uri to, say, Catalog.xml, an Exception will be thrown.
Any ideas?
Tobias