Use Application Level Styles in a Module

Topics: Prism v2 - WPF 3.5
Nov 11, 2009 at 7:37 AM

I am trying to organise my Styles in two levels.   The application wide styles I plan to put into a file in the shell and merge the resource dictionary into onto the App.axml resources.   Module specific resources I will do the same but in the modules themselves.

I am experiencing a basic problem in that if I name a style with x:Name in the App.xaml resources, when I try to access this in my module xaml file e.g. "{SharedResource xxxxx}", the compiler says it cannot find the xxxxx resource.    I know this is more of an XAML WPF issue but I guess I am not the first person wanting to do the same with Composite WPF to face the same issue.

Do i need to reference the Shell project to access the resources, do I need to merge the resources in the shell into the module resources?

Any code snippets would be appreciated.  

Nov 11, 2009 at 12:33 PM

Add style as a link resource

Nov 11, 2009 at 1:52 PM

Sorry but I am not to sure what you mean by a linked resource.

Can you add a little more detail please?

Thanks in advance

Nov 11, 2009 at 2:14 PM

1. You need to merge your resource dictionary to your application first.

2. Then, you need to use DynamicResouce instead of StaticResource.


Nov 11, 2009 at 2:28 PM

That fixed my problem.

My question is now why I need the Dynamic Resource and is there a way to get it to show in the CS designer?

Kind regards

Dec 21, 2009 at 7:09 AM

How can it be, that this works in the StockTrader_Desktop Samle Solution, using a StaticResource?

StockTraderRI.Modules.Market\TrendLine\TrendLineView.xaml(26): <TextBlock Text="{Binding TickerSymbol}" Style="{StaticResource TextBlockSectionTitle}" />

The Style "TextBlockSectionTitle" is defined in the Style.xaml of the Shell-Project.

On my solution this only works using a Dynamic Resource, otherwise i'm receiving an XamlParse Error like Steve said.

(I'm using 3 Styles in a MergedDictionary in my App.xaml in my Shell-Project, quite the same as in the Sample Solution)


Mar 4, 2010 at 12:23 PM

Anybody have an answer to this?

"How can it be, that this works in the StockTrader_Desktop Sample Solution, using a StaticResource?"

I am trying to understand when a dynamicresource is needed vs a staticresource in a CAL app.  There doesnt seem to be much guidance on this, and it seems to depend on when a module is loaded, how and where the resource is defined, etc.  I have brushes that I define at the Usercontrol.Resources level within a view that I have to reference as a dynamic resource in a CAL world, when I know that I should be able to use a StaticResource. 

Any definitive guidance on how to avoid the use of DynamicResources and yet still use scoped resource definition would be appreciated.  By Scoped, I mean resources/brushes/convertors defined at the App.xaml, the Module level and the view level.    And how each can be/has to be referenced and why.