Composite WPF (Prism) module resource data templates?

To avoid your shell app from having to know anything about your modules and your modules from reaching out into the shell in any way, I'd provide an interface to your modules like this.

To avoid your shell app from having to know anything about your modules and your modules from reaching out into the shell in any way, I'd provide an interface to your modules like this: IMergeDictionaryRegistry { void AddDictionaryResource(Uri packUri); } You'd ask for this interface in your Module code: public class MyModule : IModule { IMergeDictionaryRegistry _merger; public MyModule(IMergeDictionaryRegistry merger) { _merger = merger; } public void Initialize() { _merger. AddDictionaryResource(new Uri("pack://application:,,,/Module1;component/Module1Resources. Xaml"); } } You would then implement this in your shell to do this: public MergeDictionaryRegistry : IMergeDictionaryRegistry { public void AddDictionaryResource(Uri packUri) { Application.Current.Resources.

MergedDictionaries. Add(new DictionaryResource() { Source = packUri; }); } } And then finally, in your Bootstrapper's ConfigureContainer: public override void ConfigureContainer() { base. ConfigureContainer(); Container.RegisterType(); } This will get you the functionality you want and your Shell and your Module will remain independent of each other.

This has the added benefit of being more testable in that you have no need to spin up an Application to test your module code (just mock IMergeDictionaryRegistry and you are done). Let us know how this goes for you.

Thanks. WPF knows how to render the ViewModel by using the DataTemplate (see: msdn.microsoft.com/en-us/magazine/dd4196...#id0090097). The issue is getting the App to know about the DataTemplate in another assembly.

I've edited the post to provide more detail. – Oll Jul 23 '09 at 19:27 Oh I see what you are doing. You might have to provide some interface (IMergeDictionaryRegistration w/ a method that accepts a pack URL) to your modules and append them to your application's resource dictionary.

Just a theory. – Anderson Imes Jul 23 '09 at 22:32 Also... I'm curious how this goes for you. Let us know.

That's an interesting approach. – Anderson Imes Jul 24 '09 at 15:18 Great approach. It works perfectly.Thanks.

– Carles Company Jun 30 '11 at 11:13.

Within the initialisation of each module, you can add to the application resources: Application.Current.Resources. MergedDictionaries . Add(new ResourceDictionary { Source = new Uri( @"pack://application:,,,/MyApplication.Modules.

Module1. Module1Init;component/Resources. Xaml") }); Or if you follow a convention of each module has a resource dictionary called "Resources.

Xmal"... protected override IModuleCatalog GetModuleCatalog() { var catalog = new ModuleCatalog(); AddModules(catalog, typeof (Module1), typeof(Module2), typeof(Module3), typeof(Module4)); return catalog; } private static void AddModules(ModuleCatalog moduleCatalog, params Type types) { types.ToList() . ForEach(x => { moduleCatalog. AddModule(x); Application.Current.Resources.

MergedDictionaries . Add(new ResourceDictionary { Source = new Uri(string. Format( @"pack://application:,,,/{0};component/{1}", x.

Assembly, "Resources. Xaml")) }); }); }.

The first part of your answer requires that your module reach into the Application. I would recommend against this as it is untestable. The second approach is more appropriate.

– Anderson Imes Jun 3 '11 at 13:23.

That all seems like a lot of work! Personally, I just declare a resource dictionary in my view's UserControl. Resources section like this... That merged dictionary then points to any resources I need to include.

You'd declare your data templates in there I guess. HTH.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions