简体   繁体   English

设置WPF Toolkit DataGrid列标题的样式

[英]Styling WPF Toolkit DataGrid Column Headers

I'm having an issue styling the WPF Datagrid, I've styled the column headers (of type ColumnHeader). 我在样式WPF Datagrid时遇到问题,我已经设置了列标题(类型为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. 该列将忽略ColumnHeader样式,并且看起来不合适,因为该元素具有不同的类型,我在对象浏览器中浏览了库,但找不到该元素。 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. 以下文章中演示了该问题: http : //blogs.msdn.com/jaimer/archive/2009/01/20/styling-microsoft-s-wpf-datagrid.aspx我的意思是在右上角的元素,就在绿色第3列的右侧,并位于带有行背景箭头的单元格的上方。

Set the Width of the last column to * to make the column fill the rest of the available space. 将最后一列的Width设置为*,以使该列填充剩余的可用空间。 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>

样品

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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