2

I am setting a global style on a TextBlock, like so:

    <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>

And I am setting a global style for a GroupBox, like so:

   <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>

Here's the problem, the TextBlock for the GroupBox's header does not pick up the global TextBlock style. Here's an example GroupBox being used in the application:

   <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>

Shows the following groupbox:

MainWindow View

Why isn't the GroupBox ControlTemplate picking up the global style for the TextBlock?

Thanks in advance.

Mike Eason
  • 9,525
  • 2
  • 38
  • 63
  • Putting the TextBlock's Style and FontFamily/ColorBrush in the App.xaml works. But it doesn't work when those are in a parent resources. Not sure why – nkoniishvt Feb 06 '15 at 10:09
  • 3
    You can find an answer [here](http://stackoverflow.com/a/14503661/4049478) – nkoniishvt Feb 06 '15 at 10:16
  • It is working here after putting in Application.resource http://prntscr.com/61pbay and http://prntscr.com/61pc54 – Heena Feb 06 '15 at 11:04

0 Answers0