DataGridRowHeader ControlTemplate

Dec 8, 2008 at 8:51 PM

I am having great trouble applying a new ControlTemplate to the DataGridRowHeader. As a first step I have copied the template from the toolkit and applied it in a Style as follows, but the RowHeader just appears blank (white). I have used the same approach with the ColumnHeader successfully.

  <Style x:Key="GridRowHeaderStyle" TargetType="{x:Type toolkit:DataGridRowHeader}">
   <Setter Property="Background" Value="Red"/>
   <Setter Property="BorderBrush" Value="Green"/>
   <Setter Property="SeparatorBrush" Value="Blue"/>
   <Setter Property="Template">
     <ControlTemplate TargetType="toolkit:DataGridRowHeader">
       <toolkit:DataGridHeaderBorder IsSelected="{TemplateBinding IsRowSelected}"
                                     IsHovered ="{TemplateBinding IsMouseOver}"
                                     IsPressed="{TemplateBinding IsPressed}"
                                     Background="{TemplateBinding Background}"
                                     BorderBrush="{TemplateBinding BorderBrush}"
                                     BorderThickness="{TemplateBinding BorderThickness}"
                                     Padding ="{TemplateBinding Padding}"
                                     SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                                     SeparatorBrush="{TemplateBinding SeparatorBrush}">

        <StackPanel Orientation="Horizontal">
         <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
         <Control SnapsToDevicePixels="false"
                           Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type toolkit:DataGridRow}}, Path=(Validation.HasError), Converter={StaticResource bool2VisibilityConverter}}"
                           Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type toolkit:DataGridRow}}, Path=ValidationErrorTemplate}" />
       <Thumb x:Name="PART_TopHeaderGripper"
                   Style="{StaticResource RowHeaderGripperStyle}"/>
       <Thumb x:Name="PART_BottomHeaderGripper"
                   Style="{StaticResource RowHeaderGripperStyle}"/>

Please can someone tell me what is wrong here?


Dec 9, 2008 at 2:28 AM
Edited Dec 9, 2008 at 2:29 AM

This seems to be bug with DataGridRowHeader implementation. I have two workarounds for you....

  • Use implicit style instead of a keyed style and this shouldnt have any problems. The best way to do this would be to retain the above key style and not use it with DataGrid.RowHeaderStyle property but use it as follows instead....

        <dg:DataGrid ...>
                <Style TargetType="{x:Type dg:DataGridRowHeader}" BasedOn="{StaticResource GridRowHeaderStyle}"></Style>

  • Second approach would be to put an event setter in the style as follows

             <Style x:Key="GridRowHeaderStyle" TargetType="{x:Type toolkit:DataGridRowHeader}">
                <EventSetter Event="Loaded" Handler="DataGrid_RowHeader_Loaded"/>
                ... <!-- your remaining style -->

        private void DataGrid_RowHeader_Loaded(object sender, RoutedEventArgs e)
            DataGridRowHeader header = sender as DataGridRowHeader;
            if (header != null)

Either of these workarounds should work for you.

Dec 10, 2008 at 8:06 PM
Thanks, I've tried the first approach and that works OK for me.