Question

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?

Was it helpful?

Solution

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

        <local:MarginConverter x:Key="adjustMargin"/>
    </ResourceDictionary>
</Window.Resources>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top