2013-07-19 43 views
0

里面我有一堆的颜色定义合并成了一个styles.xaml文件:将样式为StaticResource的嵌套式的

<ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="Colors.xaml" /> 
</ResourceDictionary.MergedDictionaries> 

如果我引用从我styles.xaml这些颜色作为StaticResource,他们做工精细,所以此工程:

<Style x:Key="Timestamp" TargetType="TextBlock"> 
    <Setter Property="Foreground" Value="{StaticResource LightTextColorBrush}"/> 
</Style> 

但是,如果我尝试从包含嵌套的风格样式引用这些颜色,这是行不通的,而被忽略:

<Style TargetType="StackPanel" x:Key="FollowOnChatUserItemStyle"> 
    <Setter Property="Background" Value="White"/> 
    <Style.Resources> 
     <Style TargetType="TextBlock"> 
      <Setter Property="Foreground" Value="{StaticResource LightTextColorBrush}"/> 
     </Style> 
    </Style.Resources> 
</Style> 

在这里,我说我的StackPanel样式中的所有TextBlocks都应该使用该颜色,但它不起作用。如果我将Value="{StaticResource LightTextColorBrush}"更改为Orange这样的功能。

任何想法?

UPDATE

固定它归功于下面的反应..

我将我的资源,以App.xaml中,而不是Window.xaml这是使用它们,所以我的App.xaml包含:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Styles.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

我已经移除了window.xaml合并,我已经从StaticResource改为DynamicResource和它的作品

+1

我相信问题是合并的字典资源不在加载期间样式所应用的控件的资源树中。您需要合并App.xaml中的资源字典,或者至少在控制模板xaml文件中。 –

+0

谢谢,请参阅更新 –

+0

Matt,风格是应用于控件模板中定义的元素,在单独的文件中? –

回答

1

设置为DynamicResource而不是StaticResource并将Styles.xaml合并到App.xaml。

+0

这没有什么区别 –

+0

我把colors.xaml合并到styles.xaml的styles.xaml中,并将其合并到我的MainWindow.xaml(而不是app.xaml) –

+0

如果您已将颜色资源置于Styles.xaml中,那就可以了。你有没有在App.xaml中添加这个Styles.xaml? – Nitesh