Here I will post problems I and my colleagues met and solutions we found.

Thursday, December 11, 2008

Changing background color for header in WPF Toolkit DataGrid

Today I decided to look at DataGrid from WPF Toolkit, available at CodePlex. As you may expect, the first thing I needed to do is to change it look. I started from changing background and immediately stuck.

1. Changed Background - didn't work for everything
2. Changed RowBackground - still not everything.
3. And then I added style for DataGridColumnHeader - now I had geader, but still some small rectungles remained gray.
4. And then something strange happened, I added style for DataGridRowHeader with yellow background, but result was completely unexpected. I got what I wanted, but I still don't understand how.

Here is my result.


<dg:DataGrid x:Name="grid" Background="Red" RowBackground="Red" IsReadOnly="True" GridLinesVisibility="None" >
<dg:DataGrid.Resources>
<Style TargetType="{x:Type dgp:DataGridColumnHeader}">
<Setter Property="Background" Value="Red"/>
</Style>
<Style TargetType="{x:Type dgp:DataGridRowHeader}">
<Setter Property="Background" Value="Green"/>
</Style>
</dg:DataGrid.Resources>
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Header="Test column"/>
</dg:DataGrid.Columns>
</dg:DataGrid>

No comments: