Styling WPF Toolkit DataGrid Column Headers
I'm having an issue styling t开发者_StackOverflowhe WPF Datagrid, I've styled the column headers (of type ColumnHeader).
But when the data in the columns does not fill the full width of the grid an additional column is added to pad out the grid. This column ignores the ColumnHeader style and looks out of place presumably because the element has a different type, I've looked through the library in object browser but I can't find this element. I've also considered fixing the sizes so this column is unnecessary but thats not a viable option.
The problem is demonstrated in the following article: http://blogs.msdn.com/jaimer/archive/2009/01/20/styling-microsoft-s-wpf-datagrid.aspx The element I mean is in the top right, just to the right of green column 3 and just above the cell with the row background arrow.
This appears to have been fixed in the latest version of the grid
Set the Width
of the last column to * to make the column fill the rest of the available space. Your styles will still apply, and you won't be left with that filler column
<toolkit:DataGrid>
<toolkit:DataGrid.Resources>
<Style TargetType="{x:Type toolkit:DataGridColumnHeader}" >
<Setter Property="Foreground" Value="Red" />
</Style>
</toolkit:DataGrid.Resources>
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Header="1" />
<toolkit:DataGridTextColumn Header="2" Width="*" />
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
精彩评论