首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

关于 silverlight DataGridColumnHeader 的背景色彩不能改变 急 帮帮忙

2012-11-08 
关于 silverlight DataGridColumnHeader 的背景颜色不能改变急 帮帮忙啊我是这样写的命名空间xmlns:Primit

关于 silverlight DataGridColumnHeader 的背景颜色不能改变 急 帮帮忙啊
我是这样写的

命名空间
xmlns:Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data" 

静态资源
  <UserControl.Resources>
  <Style x:Key="gridheader" TargetType="Primitives:DataGridColumnHeader">
<Setter Property="Background">
  <Setter.Value>
  <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
  <GradientStop Color="White" Offset="0"/>
  <GradientStop Color="Yellow" Offset="0.5"/>
  <GradientStop Color="White" Offset="1"/>
  </LinearGradientBrush>
  </Setter.Value>
</Setter>
  </Style>
  </UserControl.Resources>

datagrid绑定了gridheader
<data:DataGridTextColumn Header="名称" Width="190" IsReadOnly="True" Binding="{Binding DevName, 

Mode=OneWay}" HeaderStyle="{StaticResource gridheader}"/>

为什么datagrid 的header的背景颜色没有改变呢?
大家给看看 怎么能改变header的背景颜色呢?

[解决办法]
header的背景颜色这么改是改不掉的,要在模板里改,可以参考下面这个样式修改:

HTML code
 
<Style x:Key="gridheader" TargetType="sdk:DataGridColumnHeader">
    <Setter Property="Foreground" Value="#FFB5B5B5" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="FontSize" Value="10.5" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="SeparatorBrush" Value="#FFDFE3E6" />
    <Setter Property="Padding" Value="4,4,5,4" />
    <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="sdk:DataGridColumnHeader">
      <Grid Name="Root">
        <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
          <VisualStateGroup.Transitions>
          <VisualTransition GeneratedDuration="00:00:0.1" />
          </VisualStateGroup.Transitions>
          <VisualState x:Name="Normal" />
          <VisualState x:Name="MouseOver">
          <Storyboard>
            <ColorAnimationUsingKeyFrames BeginTime="0" Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="0" Value="#FF314D64"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="0" Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">


            <SplineColorKeyFrame KeyTime="0" Value="#4C363B5C"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="0" Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
            <SplineColorKeyFrame KeyTime="0" Value="#7F363B5C"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="0" Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
            <SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/>
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
            <SplineColorKeyFrame KeyTime="00:00:00" Value="#FF363B5C"/>
            </ColorAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Offset)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.013"/>
            </DoubleAnimationUsingKeyFrames>
          </Storyboard>
          </VisualState>
        </VisualStateGroup>
        <VisualStateGroup x:Name="SortStates">
          <VisualStateGroup.Transitions>
          <VisualTransition GeneratedDuration="00:00:0.1" />
          </VisualStateGroup.Transitions>
          <VisualState x:Name="Unsorted" />
          <VisualState x:Name="SortAscending">
          <Storyboard>
            <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0"/>
          </Storyboard>
          </VisualState>
          <VisualState x:Name="SortDescending">
          <Storyboard>
            <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0"/>
            <DoubleAnimation Storyboard.TargetName="SortIconTransform" Storyboard.TargetProperty="ScaleY" Duration="0" To="-.9"/>
          </Storyboard>
          </VisualState>


        </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Fill="#FF33C421" Grid.ColumnSpan="2" Grid.RowSpan="2"/>

        <Rectangle x:Name="BackgroundGradient" Stretch="Fill" Grid.ColumnSpan="2" Grid.RowSpan="2">
        <Rectangle.Fill>

          <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
          <GradientStop Color="#FFA6A6A6"/>
          <GradientStop Color="#FF000000" Offset="1"/>
          <GradientStop Color="#FF636363" Offset="0.33500000834465027"/>
          <GradientStop Color="#FF262626" Offset="0.621"/>
          </LinearGradientBrush>

        </Rectangle.Fill>
        </Rectangle>

        <ContentPresenter
            Grid.RowSpan="2"
            Content="{TemplateBinding Content}"
            Cursor="{TemplateBinding Cursor}"
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
            Margin="{TemplateBinding Padding}"/>

        <Rectangle Name="VerticalSeparator" Grid.RowSpan="2" Grid.Column="2" Width="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" />

        <Path Grid.RowSpan="2" Name="SortIcon" RenderTransformOrigin=".5,.5" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0" Grid.Column="1" Stretch="Uniform" Width="8" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z " Fill="#FF82CAAB">
        <Path.RenderTransform>
          <TransformGroup>
          <ScaleTransform x:Name="SortIconTransform" ScaleX=".9" ScaleY=".9" />
          </TransformGroup>
        </Path.RenderTransform>
        </Path>

      </Grid>
      </ControlTemplate>


    </Setter.Value>
    </Setter>

  </Style>

热点排行