WPF in Story of Resources.

As I started to play with WPF and XAML one of first things was to get some free vector images. Those images came already formated as XAML resources:

<ResourceDictionary ...>
    <DrawingImage x:Key="Horizon_Image_Up1">
        ...
    </DrawingImage>
</ResourceDictionary>

All one needed to do was to include them as resource. I personally like to do that at application level:

<Application ...>
    <Application.Resources>
        <ResourceDictionary Source="Resources/Left1.xaml" />
        <ResourceDictionary Source="Resources/Down1.xaml" />
        <ResourceDictionary Source="Resources/Up1.xaml" />
    </Application.Resources>
</Application>

Once we do this there will be error message greeting: “Property ‘Resources’ accepts only one object.”

There are two solutions to this problem. First one is obvious - put all resources in same file. I personally tend to avoid it since I like to reuse resources in multiple projects and I hate carrying bunch of unused images.

Second solution is to merge all those dictionaries into one. Fortunately, there is simple way to do it:

<Application ...>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <Application.Resources>
                <ResourceDictionary Source="Resources/Left1.xaml" />
                <ResourceDictionary Source="Resources/Down1.xaml" />
                <ResourceDictionary Source="Resources/Up1.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

With that you have single dictionary consisting of all individual images. Do notice that, if there is same key defined in different files, only image that was defined last will be used.