views:

293

answers:

2

Hi, I'm having an issue styling the 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.

A: 

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>

Sample

qntmfred
Thanks for the reply, I'm afraid that doesn't help me in this particular situation. The View that the grid sits within doesnt have a set width, and the grid can contain quite a lot of data.
ChrisFletcher
A: 

This appears to have been fixed in the latest version of the grid

ChrisFletcher