GroupBox Header Foreground / HeaderTemplate

Nov 14, 2011 at 10:34 PM

I'm trying to change the color of the text inside the header, but I'm having a bit of difficulty doing so - either by setting the Header property to a TextBlock or by overriding the HeaderTemplate.

Both are resulting in a major change in the margins of the groupbox itself.

any insight would help lots. thanks

Nov 15, 2011 at 2:36 PM
Edited Nov 15, 2011 at 2:36 PM

Is there an easier way to accomplish this, without having to copy and edit the entire control template?

<slc:GroupBox Margin="4,-2,4,2" Padding="6,0,6,5" BorderThickness="1.5" x:Name="gbSearch" Header="Search" >
    <slc:GroupBox.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ElementName=gbSearch, Path=Header}" Foreground="WhiteSmoke" />
        </DataTemplate>
    </slc:GroupBox.HeaderTemplate>
</slc:GroupBox>
Using the TemplateBinding doesn't work. (This is probably obvious, but I'm not that proficient with xaml styling)
<slc:GroupBox.HeaderTemplate>
        <DataTemplate>
    	<TextBlock Text="{TemplateBinding Header}" Foreground="WhiteSmoke" />
        </DataTemplate>
</slc:GroupBox.HeaderTemplate>