5

I have a bunch of Xaml vector icons inside a separated .xaml. I load them inside my window using this directive:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/ScreenToGif;component/Themes/IconSet.xaml"></ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

I have lots of windows, so I would like to simply put this code inside the App.xaml.

I'm trying this:

<Application.Resources> <!-- Error, The property "Resources" can only be set once. -->
    <ResourceDictionary x:Key="IconSet"> <!--Not sure why this?-->
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Mine;component/Themes/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

<!--Here goes the rest of the file, with Style and DropShadowEffect... -->
</Application.Resources>

So here is the problem:

All examples don't use a x:Key attribute, but it gives me an error saying that I need. When I do that, it says that I can't have multiple properties Resource...

Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79

1 Answers1

25

Please see commented text

<Application.Resources>    
    <ResourceDictionary>           
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Mine;component/Themes/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>

        <!--You have to add other style here only-->

    </ResourceDictionary>

<!--Not Here-->

</Application.Resources>

Heena
  • 8,450
  • 1
  • 22
  • 40
  • 1
    Thanks, just one more thing, you need to remove the `x:Key` attribute. – Nicke Manarin Nov 30 '14 at 20:33
  • Now, I'm having some problems, for example, if I set a vector as child of a `ViewBox`, I can't set again to other `ViewBox`. I have to set the `child = null` to use elsewhere. If I just merge the dictionaries for each window, that won't happen. – Nicke Manarin Dec 01 '14 at 11:43
  • 1
    Is your vector child in resource ? http://stackoverflow.com/questions/27172730/how-to-reuse-vector-images-in-wpf-properly?noredirect=1#comment42836349_27172730 – Heena Dec 01 '14 at 11:45
  • 1
    No, but the canvas with the vector yes. It's alright now. Thanks again. `x:Shared="False"` – Nicke Manarin Dec 01 '14 at 12:08
  • 1
    Damn, I spent 15 minutes googling about this. And Heena Kishor Patil answer really works. So called intuitive error message :-D – PiotrK Apr 13 '16 at 11:28
  • 1
    @HeenaPatil Well explained. Saved my time. – nam Jan 02 '21 at 04:07