Skip to main content

Microsoft Silverlight

DataGrid entire column header (DataGridColumnHeadersPresenter) doesn't apply DataGrids' ColumnHeaderStyle!RSS Feed

(0)

Andriy Prystay
Andriy P...

Member

Member

2 points

5 Posts

DataGrid entire column header (DataGridColumnHeadersPresenter) doesn't apply DataGrids' ColumnHeaderStyle!

<data:DataGrid ColumnHeaderStyle="{StaticResource DataGridColumnHeaderDefaultStyle}">

<data:DataGrid.Columns>

<data:DataGridTextColumn Header="Testing" Binding="{Binding Path=Product}"

HeaderStyle="{StaticResource DataGridColumnHeaderDefaultStyle}"/>

</data:DataGrid.Columns>

</data:DataGrid>

Note: DataGridColumnHeaderDefaultStyle is a DataGridColumnHeader default style, which was was taken from generic.xaml in System.Windows.Controls.Data.dll resources using Reflector.

Result: Column which we declared appears with applied style, but rest of the grid's column header appears with default style.

There is no way to change style of the header!

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: DataGrid entire column header (DataGridColumnHeadersPresenter) doesn't apply DataGrids' ColumnHeaderStyle!

Hello, can you post more markup? I tried this simple style and it worked fine for auto-generated columns as well as explicit defined ones:

<Style x:Key="style1" TargetType="dataPrimitives:DataGridColumnHeader">

<Setter Property="Foreground" Value="Red"/>

</Style>

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Andriy Prystay
Andriy P...

Member

Member

2 points

5 Posts

Re: DataGrid entire column header (DataGridColumnHeadersPresenter) doesn't apply DataGrids' ColumnHeaderStyle!

Here is a markup of DataGrid in Page.xaml:

<local:DataGrid x:Name="dtGrid" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderDefaultStyle}" Width="800">

<local:DataGrid.Columns>

<local:DataGridTextColumn Header="TextColumn1" Binding="{Binding Path=Product}"/>

<local:DataGridTextColumn Header="TextColumn2" Binding="{Binding Path=Name}"/>

</local:DataGrid.Columns>

</local:DataGrid>

And here is style for DataGrid Column Header :

<Style x:Key="DataGridColumnHeaderDefaultStyle" TargetType="localprimitives:DataGridColumnHeader">

<Setter Property="Foreground" Value="#FFFFFFFF" />

<Setter Property="HorizontalContentAlignment" Value="Center" />

<Setter Property="VerticalContentAlignment" Value="Center" />

<Setter Property="FontSize" Value="10.5" />

<Setter Property="FontWeight" Value="Normal" />

<Setter Property="IsTabStop" Value="False" />

<Setter Property="SeparatorBrush" Value="#CCFFFFFF" />

<Setter Property="Padding" Value="4,4,5,4" />

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="localprimitives:DataGridColumnHeader">

<Grid x:Name="Root" Margin="0,0,0,0">

<vsm:VisualStateManager.VisualStateGroups>

<vsm:VisualStateGroup x:Name="CommonStates">

<vsm:VisualStateGroup.Transitions>

<vsm:VisualTransition GeneratedDuration="00:00:0.1" />

<vsm:VisualTransition GeneratedDuration="00:00:00.25" From="MouseOver" To="Normal"/>

</vsm:VisualStateGroup.Transitions>

<vsm:VisualState x:Name="Normal" />

<vsm:VisualState x:Name="MouseOver">

<Storyboard>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="HighlightMiddleBorder"

Storyboard.TargetProperty="(UIElement.Opacity)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>

</DoubleAnimationUsingKeyFrames>

</Storyboard>

</vsm:VisualState>

</vsm:VisualStateGroup>

<vsm:VisualStateGroup x:Name="SortStates">

<vsm:VisualStateGroup.Transitions>

<vsm:VisualTransition GeneratedDuration="00:00:0.1" />

</vsm:VisualStateGroup.Transitions>

<vsm:VisualState x:Name="Unsorted" />

<vsm:VisualState x:Name="SortAscending">

<Storyboard>

<DoubleAnimation Duration="0" To="1.0"

Storyboard.TargetName="SortIcon"

Storyboard.TargetProperty="Opacity"/>

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="SortDescending">

<Storyboard>

<DoubleAnimation Duration="0" To="1.0"

Storyboard.TargetName="SortIcon"

Storyboard.TargetProperty="Opacity"/>

<DoubleAnimation Duration="0" To="-.9"

Storyboard.TargetName="SortIconTransform"

Storyboard.TargetProperty="ScaleY" />

</Storyboard>

</vsm:VisualState>

</vsm:VisualStateGroup>

</vsm: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" Grid.ColumnSpan="3" Grid.RowSpan="2" Fill="#FF004782"/>

<Rectangle x:Name="BackgroundGradient" Stretch="Fill" Grid.ColumnSpan="3" Grid.RowSpan="1" Opacity="1" StrokeThickness="0">

<Rectangle.Fill>

<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

<GradientStop Color="#FF7FB4D4" Offset="0"/>

<GradientStop Color="#B13586B9" Offset="1"/>

</LinearGradientBrush>

</Rectangle.Fill>

</Rectangle>

<Rectangle x:Name="BottomHighlight" Stretch="Fill" Grid.ColumnSpan="3" Grid.Row="1">

<Rectangle.Fill>

<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

<GradientStop Color="#332A77A8" Offset="0.3"/>

<GradientStop Color="#FFAAD0E1" Offset="1"/>

</LinearGradientBrush>

</Rectangle.Fill>

</Rectangle>

<Rectangle x:Name="TopSeparator" Grid.ColumnSpan="3"

Height="1" Fill="#FFAFCFE3"

HorizontalAlignment="Stretch"

VerticalAlignment="Top"/>

<Grid Height="2" VerticalAlignment="Bottom"

Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2">

<Rectangle Height="1" x:Name="ColumnHeadersAndRowsSeparator"

VerticalAlignment="Top" Width="Auto" Fill="#FFAAD0E1" StrokeThickness="1" d:LayoutOverrides="GridBox"/>

<Rectangle Height="1" x:Name="ColumnHeadersAndRowsSeparator2"

VerticalAlignment="Bottom" Width="Auto" Fill="#FF003251" StrokeThickness="1" d:LayoutOverrides="GridBox"/>

</Grid>

<Grid Grid.Column="2" Grid.RowSpan="2">

<Grid.RowDefinitions>

<RowDefinition Height="0.2*"/>

<RowDefinition Height="0.6*"/>

<RowDefinition Height="0.2*"/>

</Grid.RowDefinitions>

<Rectangle x:Name="VerticalSeparator" Width="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" Margin="0,0,0,0" Grid.RowSpan="1" Grid.Row="1" />

</Grid>

<Border Height="Auto" Margin="0,-1,0,0" x:Name="HighlightMiddleBorder" Width="Auto" Grid.ColumnSpan="2" Grid.RowSpan="3" Background="#4CB0FFFB" BorderBrush="#E5000000" BorderThickness="1,1,1,1" Opacity="0">

<Border Height="Auto" x:Name="HighlightInnerBorder" Width="Auto" BorderBrush="#99FFFFFF" BorderThickness="1,1,1,1">

<Border.Background>

<RadialGradientBrush GradientOrigin="0.5,0.753">

<RadialGradientBrush.RelativeTransform>

<TransformGroup>

<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.036" ScaleY="1.431"/>

<SkewTransform CenterX="0.5" CenterY="0.5"/>

<RotateTransform CenterX="0.5" CenterY="0.5"/>

<TranslateTransform X="0.003" Y="0.17"/>

</TransformGroup>

</RadialGradientBrush.RelativeTransform>

<GradientStop Color="#FF0BEAFF"/>

<GradientStop Color="#006BC2EA" Offset="0.771"/>

</RadialGradientBrush>

</Border.Background>

<Grid Height="Auto" Width="Auto">

<Grid.RowDefinitions>

<RowDefinition Height="0.5*"/>

<RowDefinition Height="0.5*"/>

</Grid.RowDefinitions>

<Rectangle Margin="0,0,0,0" StrokeThickness="0">

<Rectangle.Fill>

<LinearGradientBrush EndPoint="0.498,1.206" StartPoint="0.497,0.132">

<GradientStop Color="#99FFFFFF" Offset="0.009"/>

<GradientStop Color="#4C93F6FF" Offset="1"/>

</LinearGradientBrush>

</Rectangle.Fill>

</Rectangle>

</Grid>

</Border>

</Border>

<ContentPresenter

Grid.RowSpan="2"

Content="{TemplateBinding Content}"

Cursor="{TemplateBinding Cursor}"

HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

Margin="{TemplateBinding Padding}"/>

<Path Grid.RowSpan="2" x: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="#FFFFFFFF">

<Path.RenderTransform>

<TransformGroup>

<ScaleTransform x:Name="SortIconTransform" ScaleX=".9" ScaleY=".9" />

</TransformGroup>

</Path.RenderTransform>

</Path>

</Grid>

</ControlTemplate>

</Setter.Value>

</Setter>

<Setter Property="FontFamily" Value="Portable User Interface"/>

<Setter Property="Background" Value="#FFFFFFFF"/>

</Style>

Now, when i compile project and see my silverlight page, two columns, which i declared appears with new style and last column(which is used to fillup the remain space of DataGrid appears with default style).

bitdisaster
bitdisaster

Member

Member

22 points

60 Posts

Re: Re: DataGrid entire column header (DataGridColumnHeadersPresenter) doesn't apply DataGrids' ColumnHeaderStyle!

I have the same problem

http://silverlight.net/forums/t/38706.aspx

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities