App.xaml中的合并字典 [英] Merged dictionaries in the App.xaml

查看:90
本文介绍了App.xaml中的合并字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单独的.xaml中有一堆Xaml矢量图标.我使用以下指令将它们加载到我的window中:

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>

我有很多窗户,所以我想简单地将此代码放在App.xaml中.

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

我正在尝试:

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

这是问题所在:

所有示例都没有使用x:Key属性,但是它给了我一个错误,说我需要. 当我这样做时,它表示我不能具有多个属性Resource ...

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

推荐答案

请参阅注释文本

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

这篇关于App.xaml中的合并字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆