我在我的App.xaml下面的一組代碼:從不同的ResourceDictionary在Silverlight
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Client.Common;component/Theme/Brushes.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/Fonts.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/CoreStyles.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/SdkStyles.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Theme/MyAppName.xaml"/>
<ResourceDictionary Source="/Client.Common;component/Controls/NavigationPanel.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
的NavigationPanel.xaml包含了風格,看起來像這樣:
<Style x:Key="NavigationPanelListBox" TargetType="ListBox">
<Setter Property="Background" Value="{StaticResource DarkBackground}" />
<Lots of XAML>
</Style>
的{StaticResource的DarkBackground}在Brushes.xaml文件(即限定第一R esource字典)。它被定義爲
<SolidColorBrush x:Key="DarkBackground" Color="#FF707176" />
在資源字典中。
在運行時,我得到以下錯誤:
Cannot find a Resource with the Name/Key DarkBackground [Line: 16 Position: 44]
行號和位置引用NavigationPanel.xaml資源字典在App.xaml中。
我可以引用其他控件的筆刷,而不是包含的資源字典。
爲什麼我不能引用或爲什麼它不解析對合並資源字典的層次更高的資源的引用?我在這裏錯過了什麼?
這是行不通的,我明白爲什麼現在可以解決,但爲什麼它不在更高級別的字典中解決?我的答案是正確的,但如果你知道這是爲什麼,我會很樂意解釋。 – 2012-02-29 20:20:39
在另一個線程發現了這一點。留在這裏爲後人。 https://social.msdn.microsoft.com/forums/windowsapps/en-US/2be9a5f6-5313-448d-a9d9-296bac42215e/using-style-defined-in-merged-dictionary-from-another-merged-dictionary?論壇= wpdevelop感謝卡米爾Nieweglowski爲此。 – Snouto 2015-05-15 10:51:28