How to add more than one resource to a XAML window?

20,147
<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources\MyStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>

        <local:MarginConverter x:Key="adjustMargin"/>
    </ResourceDictionary>
</Window.Resources>
Share:
20,147
TalkingCode
Author by

TalkingCode

Updated on July 09, 2022

Comments

  • TalkingCode
    TalkingCode almost 2 years

    I have a little problem right now and I don't know how to fix it. I want to add two resources to a window. One is a XAML File style resource, the other a ValueConverter Class.

    Both of them work if I use only one resource at a time:

     <Window.Resources>
        <ResourceDictionary Source="Resources\MyStyles.xaml" />
     <Window.Resources>
    

    or

    <Window.Resources>
        <local:MarginConverter x:Key="adjustMargin"/>
    </Window.Resources>
    

    But if I try something like this:

    <Window.Resources>
        <local:MarginConverter x:Key="adjustMargin"/>
        <ResourceDictionary Source="Resources\MyStyles.xaml" />
    </Window.Resources>
    

    I get the message the resource is already been set and can not set twice.

    I have no idea how to get this done. Is there something like a resource group?

  • TalkingCode
    TalkingCode about 15 years
    Thanks a lot. I tried many things but to put the Converter into the ResourceDictionary was not one of them.