里面我有一堆的颜色定义合并成了一个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
和它的作品
我相信问题是合并的字典资源不在加载期间样式所应用的控件的资源树中。您需要合并App.xaml中的资源字典,或者至少在控制模板xaml文件中。 –
谢谢,请参阅更新 –
Matt,风格是应用于控件模板中定义的元素,在单独的文件中? –