wpf App.xaml 中的合并字典
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27215155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merged dictionaries in the App.xaml
提问by Nicke Manarin
I have a bunch of Xaml vector icons inside a separated .xaml. I load them inside my windowusing this directive:
我有一堆 Xaml 矢量图标在一个单独的.xaml. 我window使用这个指令将它们加载到我的内部:
<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.
我有很多窗口,所以我想简单地将此代码放在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:Keyattribute, but it gives me an error saying that I need.
When I do that, it says that I can't have multiple properties Resource...
所有示例都不使用x:Key属性,但它给了我一个错误,说我需要。当我这样做时,它说我不能拥有多个属性Resource......
回答by Heena Patil
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>

