I have four datagrids on a Silverlight 4 page. I am trying to set different styles of column headings for each grid. I found this XAML that works when I embed it in each DataGrid inside the <sdk:DataGrid.ColumnHeaderStyle> tags:
<Style TargetType="primitives:DataGridColumnHeader" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="primitives:DataGridColumnHeader"> <Grid Name="Root"> <vsm:VisualStateManager.VisualStateGroups> <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 Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" /> </Storyboard> </vsm:VisualState> <vsm: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> </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="2" Grid.RowSpan="2"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Color="Transparent" Offset="0" /> <GradientStop Color="LavenderBlush" Offset="1" /> </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 "> <Path.Fill> <SolidColorBrush Color="#FF444444" /> </Path.Fill> <Path.RenderTransform> <TransformGroup> <ScaleTransform x:Name="SortIconTransform" ScaleX=".9" ScaleY=".9" /> </TransformGroup> </Path.RenderTransform> </Path> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
When I put it in a separate resource dictionary and delete the above tags, it also works by applying to all four headers. But when I try to create a specific version of this resource dictionary, but changing the first line to this:
<Style x:Key="ADGridColumnHeader" TargetType="primitives:DataGridColumnHeader" >
and adding this to the DataGrid:
ColumnHeaderStyle="PhoneMasterGridColumnHeader"
I get an error: XamlParseException occurred: Failed to create "System.Windows.Style" from the text "PhoneMasterGridColumnHeader". I canβt understand what happened. I'm still struggling to deal with styles and resource dictionaries. Any idea?
serialhobbyist
source share