我在TextBlock上设置全局样式,如下所示:
<FontFamily x:Key="DefaultFontFamily">Consolas</FontFamily>
<SolidColorBrush x:Key="DefaultFontColour" Color="#96EED5"/>
<Style TargetType="TextBlock">
<Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}"/>
<Setter Property="Foreground" Value="{DynamicResource DefaultFontColour}"/>
</Style>
我正在为GroupBox设置一个全局样式,如下所示:
<Style TargetType="GroupBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupBox">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding Header}"/>
<Rectangle Grid.Row="1" Height="1" Fill="{TemplateBinding Foreground}"/>
<ContentPresenter Grid.Row="2"
Margin="0,6,0,0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
问题是,GroupBox标题的TextBlock没有获取全局TextBlock样式。以下是应用程序中使用的GroupBox示例:
<GroupBox Header="SOME HEADER HERE">
<TextBlock TextWrapping="Wrap">
This is a very very very very
very very very very very very
very very very very very very
very very very very very very
long string.</TextBlock>
</GroupBox>
显示以下组框:
为什么GroupBox ControlTemplate没有为TextBlock获取全局样式?
提前致谢。