App.xaml中合并的词典

时间:2014-11-30 16:03:40

标签: wpf xaml app.xaml mergeddictionaries

我在分隔的.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 ...

1 个答案:

答案 0 :(得分:17)

请参阅评论文字

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