Using Setter to set background of datagrid header-VBForums
Results 1 to 2 of 2

Thread: Using Setter to set background of datagrid header

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    21

    Using Setter to set background of datagrid header

    I am using SL 4. I have created a datagrid but I cannot set the Background Color in either the body of the grid or the header.

    Here is a snippet of my code;
    <sdkataGrid.ColumnHeaderStyle>
    <Style TargetType="sdkataGridColumnHeader">
    <Setter Property="FontFamily" Value="Georgia"></Setter>
    <Setter Property="Foreground" Value="Maroon"></Setter>
    <Setter Property="FontWeight" Value="Bold"></Setter>
    <Setter Property="Background" Value="Maroon"></Setter>
    </Style>
    </sdkataGrid.ColumnHeaderStyle>

    It all works except the background.

    Does anyone have any ideas
    Pete

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Using Setter to set background of datagrid header

    There is no Background property to you'll have to customize its template.

    Namespace:

    Code:
    xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
    Code:
    <Style x:Name="ColumnHeader" TargetType="primitives:DataGridColumnHeader">
    	<Setter Property="FontFamily" Value="Georgia" />
    	<Setter Property="FontWeight" Value="Bold" />
    	<Setter Property="Foreground" Value="Maroon" />
    	<Setter Property="Template">
    		<Setter.Value>
    			<ControlTemplate TargetType="primitives:DataGridColumnHeader">
    				<StackPanel Orientation="Vertical">
    					<Border Name="HeaderSeparator" VerticalAlignment="Stretch" Background="Maroon">
    						<TextBlock Text="{TemplateBindingContent}" />
    					</Border>
    				</StackPanel>
    			</ControlTemplate>
    		</Setter.Value>
    	</Setter>
    </Style>
    You may want to check out this link for a fancier example that was changed using Blend.

    http://stackoverflow.com/questions/3...in-silverlight

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.