How-to: Setup your XAML-Project using multiple resource dictionaries

If you ever worked with a larger XAML Project the entries in your resource dictionaries will start to pile up and it’s really a pain to find where you put some Brush or Style or whatever.

Wouldn’t it be nice if you could separate your resources into different kinds and manage them in there own files? Well of course you can – and it’s very easy but there are some steps to remember.

I like having my resource dictionaries in a separate folder within my projects – I guess most people call this “Assets” but name mine “Resources” (go figure) – so first create a new folder with whatever name you want and put a new “Resource Dictionary” in there:


(Note I’m using the VS11 beta but it’s exactly the same in VS2010)

The file opens like this:

<ResourceDictionary xmlns=""

And you can begin filling your resources in there (of course there is support in Blend for this too).

The next step is telling your main resource-dictionary (usually in the App.xaml file) to merge with your newly created dictionary. This is done using something like the following:

                    <Color x:Key="Redish" R="155" />
                <ResourceDictionary Source="Resources/Templates.xaml" />

As you can see – all that there is to it is using the ResourceDictionary.MergedDictionaries collection and adding dictionaries. In this case I use one “in-place” and the Templates dictionary I created in the last step (setting the Source property).

That’s it – now you can use those resources as if you had defined them in your local or App resources.