How to use Application.Resources and also ResourceDictionaries in WPF


The help page in MSDN is at:

I originally got this wrong, by trying to create a new Resource dictionary and placing the XAML <Application.Resources> into this new file.
When you create a new WPF application, an Application.xaml file is created automatically. This already contains an <Application.Resources> section, so just add in your new resources direct into here.

How to use Resource Dictionaries

Create Resource Dictionary, possibly putting it in a different folder, perhaps named Assets.
Then in Application.xaml

<ResourceDictionary Source=”Assets\Dictionary1.xaml” />
<ResourceDictionary Source=”Assets\Dictionary2.xaml” />

<–Seem to be only able use Resoure Dictionary or Application.Resources not a mix of both
So Following line is invalid, because of following ResourceDictionaries
May be possible if a Key is used somewhere>–>
<!–<Brush x:Key=”myColorYellow”>Yellow</Brush>–>

Error 1

If on a window or page and “The designer does not support loading dictionaries that mix “ResourceDictionary” items without a key and other items in the same collection”

Solution 1:

Put the other resources inside the ResourceDictionary even if they are designed there.

With thanks to

How to store Resource Dictionaries in a separate assembly and use them

In the following example of use. RDL01 is an external assembly. The word “component” is there as seen here.

<ResourceDictionary Source=”/RDL01;component/Dictionary1.xaml”></ResourceDictionary>
<Button Content=”Hello” Width=”100″ Height=”50″></Button>

How to use the Property Windows for controls to use and extract Resources

Use extract value to resource

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: