【问题标题】:Merged dictionaries in the App.xamlApp.xaml 中的合并字典
【发布时间】:2015-01-28 16:14:58
【问题描述】:

我在分隔的.xaml 中有一堆 Xaml 矢量图标。我使用这个指令将它们加载到我的window 中:

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

我有很多窗口,所以我想简单地将这段代码放在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...

【问题讨论】:

    标签: wpf xaml app.xaml mergeddictionaries


    【解决方案1】:

    请看注释文字

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

    【讨论】:

    • 谢谢,还有一件事,您需要删除x:Key 属性。
    • 您的矢量孩子在资源中吗? stackoverflow.com/questions/27172730/…
    • 否,但带有矢量的画布是。现在好了。再次感谢。 x:Shared="False"
    • 该死,我花了 15 分钟在谷歌上搜索。 Heena Kishor Patil 的回答确实有效。所谓的直观错误消息:-D
    • @HeenaPatil 解释得很好。节省了我的时间。
    猜你喜欢
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    相关资源
    最近更新 更多