Silverlight 3 中合并资源字典的正确使用 [英] Proper usage of Merged Resource Dictionaries in Silverlight 3
问题描述
正如我所读:http://msdn.microsoft.com/en-us/library/cc903952(VS.95).aspx,特别是标有使用资源字典的前向引用"的部分:
As I read: http://msdn.microsoft.com/en-us/library/cc903952(VS.95).aspx, specifically the section labeled "Forward References With a ResourceDictionary":
来自内部的静态资源引用任何给定的资源字典必须引用已经存在的资源在词法定义之前资源参考.前向引用无法通过静态解决资源参考.为此原因,如果您使用静态资源引用,你必须设计你的资源字典结构使得资源用于进一步按资源使用定义在或附近各自的开始资源字典.
Static resource references from within any given resource dictionary must reference a resource that has already been defined lexically before the resource reference. Forward references cannot be resolved by a static resource reference. For this reason, if you use static resource references, you must design your resource dictionary structure such that resources intended for further by-resource use are defined at or near the beginning of each respective resource dictionary.
这是否意味着我不能在我的 App.xaml 中做这样的事情:
Does this mean that I cannot do something like this in my App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Colors.xaml"/>
<ResourceDictionary Source="Assets/Brushes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Brushes.xaml 中包含 SolidColorBrush、LinearColorBrush 等的定义是指 Colors.xaml 中定义的颜色吗?
Where Brushes.xaml contains SolidColorBrush, LinearColorBrush, etc, definitions that refer to the colors defined in Colors.xaml ?
例如
<SolidColorBrush x:Key="OrangeRedBrush" Color="{StaticResource AppOrangeRed}"/>
?
我在 Colors.xaml 中定义我的颜色,例如:
I define my colors in Colors.xaml like:
<Color x:Key="AppOrangeRed">#FFBF3C1F</Color>
我收到一个运行时错误,指出它无法找到键为AppOrangeRed"的资源.
I'm getting a runtime error that states it cannot find a resource with key 'AppOrangeRed' for instance.
组织颜色和画笔以便重复使用的最佳实践是什么(在适当的情况下,我知道颜色是结构,画笔是参考对象,在 http://weblogs.manas.com.ar/spalladino/2009/03/02/silverlight-xaml-指南/)
What are the best practices for organizing Colors and Brushes so they can be reused (where appropriate, and I understand that colors are structs and brushes are reference objects, explained in http://weblogs.manas.com.ar/spalladino/2009/03/02/silverlight-xaml-guidelines/)
谢谢罗布
推荐答案
我现在明白了一点.如果您有多个有时相互引用的应用程序范围资源,则需要 (1) 在 App.xaml 中声明的主字典中对它们进行排序,AND 您需要在每个文件中包含一个部分拉入依赖部分.因此,如果我有三个文件,例如 Brushes.xaml、ScrollViewerStyles.xaml 和 ComboBoxStyles.xaml,而 ComboBoxStyles.xaml 依赖于前两个,我只需要添加到该文件的顶部:
I understand it now a little clearer. If you have multiple application-scope resources that sometimes refer to each other, you need to (1) order them in the master dictionary declared in App.xaml, AND you need to include in each file a section that pulls in the dependent pieces. So if I have three files for instance, Brushes.xaml, ScrollViewerStyles.xaml, and ComboBoxStyles.xaml, and ComboBoxStyles.xaml depends on the former two, I would need to simply add to the top of that file:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brushes.xaml"/>
<ResourceDictionary Source="ScrollViewerStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
这篇关于Silverlight 3 中合并资源字典的正确使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!