从 Silverlight 中的不同 ResourceDictionary 引用 ResourceDictionary 中的资源 [英] Referencing a resource in a ResourceDictionary from a different ResourceDictionary in Silverlight
问题描述
我的 App.xaml 中有以下代码集:
I have the following set of code in my App.xaml:
<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 包含如下所示的样式:
The NavigationPanel.xaml contains a style that looks like this:
<Style x:Key="NavigationPanelListBox" TargetType="ListBox">
<Setter Property="Background" Value="{StaticResource DarkBackground}" />
<Lots of XAML>
</Style>
{StaticResource DarkBackground} 在 Brushes.xaml 文件(即第一个资源字典)中定义.它被定义为
The {StaticResource DarkBackground} is defined in the Brushes.xaml file (i.e. the first resource dictionary). It is defined as
<SolidColorBrush x:Key="DarkBackground" Color="#FF707176" />
在资源字典中.
在运行时,我收到以下错误:
At runtime, I get the following error:
Cannot find a Resource with the Name/Key DarkBackground [Line: 16 Position: 44]
行号和位置引用了 app.xaml 中的 NavigationPanel.xaml 资源字典.
The line numbers and position references the NavigationPanel.xaml resource dictionary in the app.xaml.
我可以从其他控件引用画笔,但不能引用包含的资源字典.
I can reference the brush from other controls, just not the included resource dictionary.
为什么我不能引用或者为什么它不能解析对合并资源字典层次结构中更高的资源的引用??我在这里错过了什么?
Why can I not reference or why does it not resolve the reference to a resource that is higher in the heirarchy of the merged resource dictionary?? What am I missing here?
推荐答案
您是否在 NavigationPanel
字典中的任何资源中引用了 DarkBackground
画笔?
Are you referencing the DarkBackground
brush in any of the resources in the NavigationPanel
dictionary?
如果您愿意,您可能需要将 Brushes
资源字典合并到 NavigationPanel
字典中.
If you are you might need to merge the Brushes
resource dictionary into the NavigationPanel
dictionary.
所以在 NavigationPanel 字典中.
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Client.Common;component/Theme/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
这篇关于从 Silverlight 中的不同 ResourceDictionary 引用 ResourceDictionary 中的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!