Merged dictionaries in the App.xaml

点点圈 提交于 2019-12-20 03:16:50

问题


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...


回答1:


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>



来源:https://stackoverflow.com/questions/27215155/merged-dictionaries-in-the-app-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!