简体   繁体   中英

Styling WPF Toolkit DataGrid Column Headers

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.

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>

样品

这似乎已在最新版本的网格中得到修复

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM