这是因为:Content Presenter
为显示内容创造了一个文本Block,而且由于文本Block在视觉树中,它将研究应用水平的资源。 如果你在申请一级界定了文本Block的风格,则将适用于控制范围内的这些文本Block。
一项工作是界定<代码>DataTemplate>>,用于<代码>System.String,其中我们可以明确使用默认文本Block显示内容。 你可以把该数据模板放在同一个词典中,你界定了文本Block风格,以便这一数据模板将适用于你风格的任何内容。
在你的申请资源中加上这一点,它应当为你工作——
<DataTemplate DataType="{x:Type system:String}">
<TextBlock Text="{Binding}">
<TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}"/>
</TextBlock.Resources>
</TextBlock>
</DataTemplate>
如果尚未申报,可在您的xaml中申报一个名称空间,
xmlns:system="clr-namespace:System;assembly=mscorlib"
www.un.org/Depts/DGACM/index_spanish.htm EDIT :检查其工作的样本。
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Red"/>
</Style>
<DataTemplate DataType="{x:Type system:String}">
<TextBlock Text="{Binding}">
<TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}"/>
</TextBlock.Resources>
</TextBlock>
</DataTemplate>
<Style TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="Yellow"/>
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="Blue"/>
</Style>