Shared Resources Dictionaries Runtime Loading Bug

Topics: Prism v4 - WPF 4
Dec 1, 2011 at 11:08 PM
Edited Dec 1, 2011 at 11:10 PM


I have several questions regarding the use os shared resources in a modular application, can anybody help me?


I have a modular project divided in three main concepts, like this:

Application (project shell)

Modules (projects MainModule and ScannerModule)

Infrastructure (projects Infrastructure and Resources)


In order to organize and reuse resources, all common resources and default styles are placed in the Resources project. The Application (Shell) has a reference to it and my modules too, but the modules does not have a reference to the Shell and either the Shell has a reference to them, the modules (Main and Scanner) are discovered through an app.config file.

In my App.xaml (in Shell) i merge the DefaultTheme.xaml resourcedictionary from Resources so that all the resources files merged in DefaultTheme are loaded in the application.

Until now i believe this is the common approach for sharing resources right? Or am I wrong?

Now comes the problem. When i load the main view of the application (ShellView) in the Visual Studio Designer, all is fine. All my default styles are loaded correctly in the designer (of course the views from the module does not appear yet). But when I run the application, only the elements in the ShellView that are not composed (and appeared correctly in the designer) applies the default style defined in the Resources project, none of the elements in the views of my modules load the style.

The bizarre part is that when I open the module views in the designer, the default styles are applied in it! Even without any reference to it in any of the views, Visual Studio appears to consider the resources merged in the App.xaml resources of the StartUp Project and load them just fine, only during runtime they do not load.

I tried to convert the Resource project into an module and make the logic modules depend on it but makes no diference. I put the default styles directly in the App.xaml of the Application but that doesn't help either. The ONLY way to make them work on runtime was:

- create named styles and apply it as staticresources (this demonstrates that they CAN find the resources merged in the App.xaml) but is frustrating referencing the style for every single element.

- keep the default style in the resources and reference in the module views with a staticresource to the {x:Type TargetType}.

ex: <Button Style={StaticResource {x:Type Button}} /> in the module view. This also shows that the default styles are defined and acessible! (because they create implicit names with the TargetType names).

I don't know what else I can do. Merge the theme in every module view is not an option because it will create it for every element. Also, it didn't work either without the workaround described before!

PS: I've already read of the optimization bug in the MergedResources logic and the App.xaml has a dummy style in it. And also sorry for the bad english!

Any suggestions?



Dec 2, 2011 at 8:25 AM



Can you post your project ???

Dec 2, 2011 at 5:51 PM
mkadoussi wrote:



Can you post your project ???

Unfortunately it's a company project and I can't post the project. But i made a new solution with the same concept of the original project to demonstrate what is happening.

I uploaded it the example to skydrive: Example Link

Please let me know what you find.

I saw a post in a blog where someone claims that some regionadapters (itemscontrol and selectors) break the style hierarchy because they do not verify in the item has an null itemcontainerstyle before setting it as the item style in the Adapt method, so it overrides the current item inherited style with null.

I inspected the Prism code and couldn't find such line of code in the Adapt method.

Thanks in advance.