WPF - Using resource dictionaries in modules

Topics: Prism v4 - WPF 4
Apr 23, 2014 at 10:18 AM
Edited Apr 23, 2014 at 10:19 AM
I have had a look at:


But I do not have app.xaml in my Modules? Is this still the best way to do this? If so how do I add the app.xaml file?

I am on Prism 5.0.

I see the StockTrader sample seems to work, but I'm not sure how.
Apr 23, 2014 at 3:16 PM
Hi James,

I am not sure what would you be trying to accomplish. WPF applications would not need to have one App.xaml file on every Module in order to properly run. Based on the article you mentioned, you may define the Resource Dictionaries on each Module with the only objective of having the resources available at Design time.

When working at runtime, the App.xaml file that would run and configure the Resource Dictionaries would only be the one defined in the Shell project. You may find related information on the follwing MSDN Prism Guide chapter:

If you could tell us in more detail the goals you would be trying to achive, I would be able to give you further support.

I hope this helped,

Gabriel Ostrowsky.
Apr 23, 2014 at 3:47 PM
Yes I understand that. I am looking purely for getting the Designer working.
Apr 23, 2014 at 7:21 PM
Hi James,

Thanks for the response. Adding an App.xaml file on the desired Modules should be quite straightforward. Damian Cherubini's article references to a post of "How To define module-specific resource dictionaries", which explains how to add an App.xaml file on each Module with the Resources Dictionary defined on it. Find the blogpost in the following link:

Moreover, the mentioned post above provides a small sample on which you may see the workaround properly working.

However, the Reference Implementation provides another approach in order to make the resources work at DesignTime which is based on a Visual Studio behaviour for Modules that would be referenced in the main project's solution. The following discussions may help you understand how the approach works:

Gabriel Ostrowsky
Apr 24, 2014 at 11:23 AM
Thanks for your help!

I see in your first article it says:

"You may have noticed that some times modules also contain an App.xaml file. This file isn’t loaded when Prism modules are loaded; only one Application class is instantiated, and that’s the one in the Shell project.


So, while defining the resources in the module’s App.xaml file would make them show in the designer, they wouldn’t work when the application is ran. Going backwards a little, Application.Current.Resources can be accessed from anywhere inside the Prism application (even modules), and the ResourceDictionary class supports adding new entries! So you might see where I’m going with this…"

But it doesn't explain how to get that file on there?? It seems to also show a SilverLight solution so I don't know if this is any different? He then goes on how to actually add the resource dictionary to Application resources, which I don't want to do because this is just for design time.

I see on your second link the Stock Trader example app, has references to it's module's, which is why it works. Is this best practice??

And your third link suggests using the App.xaml file again in Modules as it is ignored on full running of the application. Bug again I'm not sure on how to add this correctly.

Sorry to be a pain!
Apr 24, 2014 at 7:39 PM
Hi James,

Basically, the only negative connotation of the StockTrader approach would be that it couples all the Module projects when they could possibly be kept decoupled, for example when using xap files in Silverlight. This would be the reason for the existence of Damian and Guido's workaround. Nevertheless, if you would like to work with the Designer and then clean the solution for release, you could simply remove the corresponding references from the main project, and no other source code modification would need to be performed.

Regarding the workaround of adding the App.xaml files on each Module, it would work for both WPF and Silverlight solutions. So you would be able to copy the highlighted updates from the sample into your solution. In order to properly configure it, you should perform the following changes:
  • From the Module side, you would need to add the App.xaml file with the Resource Dictionary defined, and the create the Resources.xaml file which would be loaded. Then, add the ModuleResource attribute on the IModule's implementation class.
  • From the Main project side, create the ResourceLoader service and the ModifiedModuleInitializer. Register these types in the Container from the Bootstrapper's ConfigureContainer() method as follows:
protected override void ConfigureContainer()
    this.Container.RegisterType<IResourceLoader, ResourceLoader>();
    this.Container.RegisterType<IModuleInitializer, ModifiedModuleInitializer>();

  • Lastly, create an Infrastructure project, and add the IResourceLoader and ModuleResourceAttribute classes. Reference the Infrastructure project from every Module and the Main project.
With the mentioned changes, the solution would be able to add all the resources definitions from the diferent Modules into the ResourcesDictionaries and properly resolve the StaticResources to run at DesignTime.

I hope you find this useful,

Gabriel Ostrowsky