Xaml MergedDictionaries无法找到每个人的资源

时间:2013-01-04 15:44:36

标签: xaml windows-runtime dictionary

我的两个词典存在问题:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Styles1.xaml"/>
    <ResourceDictionary Source="Styles2.xaml"/>
</ResourceDictionary.MergedDictionaries>

当我在第一个字典中设置一个资源时,例如Color。 然后它不会在第二个字典中找到它????

首先:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Color x:Key="ApplicationPageBackgroundColor">#FFFFFFFF</Color>
    <SolidColorBrush x:Key="ApplicationPageBackgroundColorBrush" Color="{StaticResource ApplicationPageBackgroundColor}" />
</ResourceDictionary>

第二:( Setter Property =“Background”Value ....生成错误)

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="LayoutRootStyle" TargetType="Panel">
        <Setter Property="Background" Value="{StaticResource ApplicationPageBackgroundColorBrush}" />
    </Style>
</ResourceDictionary>

如果我将它们放在相同的字典中,那么有什么建议吗?

1 个答案:

答案 0 :(得分:0)

Styles2.xaml没有提及Styles1.xaml,反之亦然。要使StaticResource工作,字典条目必须在使用点静态可见(“在范围内”)。以同样的方式,您无法引用稍后在同一XAML文件中定义的资源。

在WPF中,DynamicResource可能会执行您想要的操作,但在WinRT中不可用。您必须将第一个资源合并到第二个(并且没有任何循环依赖关系),或者将共享部分放在两个可见的位置(例如Application.Resources)。