Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

Hi

I defined a Style in my XAML to be used on all Groupboxes, but there's ONE groupbox's background property that has to be different from the others. I tried setting this property in the code-behind, but no luck. Any ideas?

Here's the code for the style:

<!--A style that formats all groupboxes-->
<Style TargetType="GroupBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupBox">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="White" BorderThickness="2,2,2,1" CornerRadius="0,12,0,0" >
<ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" />
</Border>
<Border Grid.Row="1" BorderBrush="White" BorderThickness="2,0,2,2" CornerRadius="0,0,0,12" >
<ContentPresenter Margin="4" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Posted
Updated 25-Aug-09 10:17am
v2

1 solution

If all you need to do is have one groupbox that behaves slightly differently to the others in it's styling, all you need to do is create a new style that targets a groupbox, and give it a key. By default, (as long as you add it after the groupbox above) it will inherit the settings of the groupbox, and you can change the background property as appropriate. All you need do then is apply the style to the groupbox in question - you have the key to use here.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900