silverlight datagrid 的ColumnHeader 背景色没用
以下是代码:
<data:DataGrid.ColumnHeaderStyle>
<Style TargetType ="prim:DataGridColumnHeader">
<Setter Property="FontSize" Value="12"></Setter>
<Setter Property="Background" Value="Red"></Setter>
</Style>
</data:DataGrid.ColumnHeaderStyle>
不变色啊,急!!!
[解决办法]
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<UserControl.Resources>
<Style x:Key="DataGridColumnHeaderStyle1" TargetType="sdk:DataGridColumnHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="sdk:DataGridColumnHeader">
<Grid x:Name="Root">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Rectangle x:Name="BackgroundRectangle" Grid.ColumnSpan="2" Fill="#FF1F3B53" Stretch="Fill"/>
<Rectangle x:Name="BackgroundGradient" Grid.ColumnSpan="2" Stretch="Fill" Fill="Red"/>
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentPresenter Content="{TemplateBinding Content}"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid AutoGenerateColumns="False" Height="189" HorizontalAlignment="Left" Margin="42,42,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="322">
<sdk:DataGrid.Columns>
<sdk:DataGridCheckBoxColumn HeaderStyle="{StaticResource DataGridColumnHeaderStyle1}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="AAA" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="BBB" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="CCC" />
<sdk:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="DDD" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</Grid>
</UserControl>