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;
<sdk:DataGrid.ColumnHeaderStyle>
<Style TargetType="sdk:DataGridColumnHeader">
<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>
</sdk:DataGrid.ColumnHeaderStyle>
It all works except the background.
Does anyone have any ideas
Pete
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