Hi folks, 
I have a WPF Datagrid in a WPF Project Window. I have populated the grid with a datatable, and autogenerated the columns (unfortunately a necessity) and have a requirement to change the header colour of the columns dependant on certain other factors.
I have a list of the coulmn names that need highlighted, and would easily be able to figure out their indexes based on this (as I generated them myself in the datagrid)
However, I can't seem to get the column header to change colour, this has to be done in the code as I don't know at design time which columns will need highlighted. I already have a bit of a template on the header... not sure if that is "over-riding" what I am trying to do.
Grid:
	Grid header style (roates text)
	And this is what I have tried so far to get the column header to change (called on the "Window_Activat  ed" event as that is called after the constructor when the grid/wpf tree is actually built)
	Any help would REALLY be appreciated.
Cheers,
Mark
					I have a WPF Datagrid in a WPF Project Window. I have populated the grid with a datatable, and autogenerated the columns (unfortunately a necessity) and have a requirement to change the header colour of the columns dependant on certain other factors.
I have a list of the coulmn names that need highlighted, and would easily be able to figure out their indexes based on this (as I generated them myself in the datagrid)
However, I can't seem to get the column header to change colour, this has to be done in the code as I don't know at design time which columns will need highlighted. I already have a bit of a template on the header... not sure if that is "over-riding" what I am trying to do.
Grid:
Code:
	<DataGrid FrozenColumnCount="1"  AutoGenerateColumns="True" Grid.Row="1" AlternationCount="2" HeadersVisibility="Column" Name="dgSkillsMatrix" Margin="0,0,2,1" HorizontalGridLinesBrush="White" VerticalGridLinesBrush="White" AlternatingRowBackground="#FFD0D0EB" RowBackground="#FFECECF5" FontSize="10.5" Grid.ColumnSpan="1" CellStyle="{StaticResource CellHighlighterStyle}" ColumnHeaderStyle="{StaticResource dataGridColumnHeader}" />
Code:
	<DataTemplate x:Key="RotateHeaderTemplate" >
	<TextBlock Text="{Binding}" Foreground="Blue" >
            <TextBlock.LayoutTransform>
                <RotateTransform Angle="-90" />
            </TextBlock.LayoutTransform>
	</TextBlock>
</DataTemplate>
Code:
	Style newStyle = new System.Windows.Style()
			{
				TargetType = typeof(DataGridColumn)
			};
			//SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F70F49"))
			newStyle.Setters.Add(new Setter(DataGridColumn.HeaderStringFormatProperty, new SolidColorBrush(Colors.Red)));
			this.dgSkillsMatrix.Columns[4].HeaderStyle = newStyle;
Cheers,
Mark
Comment