locked
How to Change the GroupBox Header Color In Expression Blend 2 RRS feed

  • Question

  • hi,
         I am new to WPF ,i am using Expression Blend2 .i want to change the groupbox header color,Can any one suggest me how to change the groupbox header color.

    Regards,
    Sharath kumar
    Monday, November 23, 2009 7:38 AM

Answers

  • I don't use Blend 2, but I imagine that this would still work.

    You can change the background color easily on a per-GroupBox basis by using XAML like this:

    <GroupBox Margin="128,104,136,78">
    	<GroupBox.Header>
    		<Label Content="GroupBox" Background="Red"></Label>
    	</GroupBox.Header>
    </GroupBox>


    The obvious disadvantage is that if you want a specific color for your GroupBox backgrounds application-wide, you'd have to do this for each and every one.  That's where a Style will help you out immensely:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="GroupBoxHeaderColor.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    
    	<Window.Resources>
    		<Style x:Key="RedGroupBoxBackground" TargetType="{x:Type GroupBox}">
    			<Setter Property="HeaderTemplate">
    				<Setter.Value>
    					<DataTemplate>
    						<Label Content="GroupBox" Background="Red" />
    					</DataTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    	</Window.Resources>
    
    	<Grid x:Name="LayoutRoot">
    		<GroupBox Margin="128,104,136,78" Style="{StaticResource RedGroupBoxBackground}"></GroupBox>
    	</Grid>
    </Window>


    You will also need to use a Binding for this to bind the Content value to that of the GroupBox, so that whatever you set to be the header value will appear properly.  I'm not quite that far in the databinding area, so I'm looking into it.  Hope this helps you out.
    • Marked as answer by sharathkumar11 Tuesday, November 24, 2009 4:32 AM
    Monday, November 23, 2009 3:21 PM

All replies

  • I don't use Blend 2, but I imagine that this would still work.

    You can change the background color easily on a per-GroupBox basis by using XAML like this:

    <GroupBox Margin="128,104,136,78">
    	<GroupBox.Header>
    		<Label Content="GroupBox" Background="Red"></Label>
    	</GroupBox.Header>
    </GroupBox>


    The obvious disadvantage is that if you want a specific color for your GroupBox backgrounds application-wide, you'd have to do this for each and every one.  That's where a Style will help you out immensely:

    <Window
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	x:Class="GroupBoxHeaderColor.MainWindow"
    	x:Name="Window"
    	Title="MainWindow"
    	Width="640" Height="480">
    
    	<Window.Resources>
    		<Style x:Key="RedGroupBoxBackground" TargetType="{x:Type GroupBox}">
    			<Setter Property="HeaderTemplate">
    				<Setter.Value>
    					<DataTemplate>
    						<Label Content="GroupBox" Background="Red" />
    					</DataTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    	</Window.Resources>
    
    	<Grid x:Name="LayoutRoot">
    		<GroupBox Margin="128,104,136,78" Style="{StaticResource RedGroupBoxBackground}"></GroupBox>
    	</Grid>
    </Window>


    You will also need to use a Binding for this to bind the Content value to that of the GroupBox, so that whatever you set to be the header value will appear properly.  I'm not quite that far in the databinding area, so I'm looking into it.  Hope this helps you out.
    • Marked as answer by sharathkumar11 Tuesday, November 24, 2009 4:32 AM
    Monday, November 23, 2009 3:21 PM
  • hi,
          Thanks for Your Response.

    Regards,
    Sharath kumar
    Tuesday, November 24, 2009 4:32 AM
  • Glad it helped!
    Wednesday, November 25, 2009 2:45 PM