仅一栏的特殊网格线样式

编程入门 行业动态 更新时间:2024-10-28 17:25:39
本文介绍了仅一栏的特殊网格线样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在 DataGrid ?特别是,我希望一列的左边界有一条双线.

How would I set a custom grid line style on just one column of a DataGrid? In particular, I'd like one column to have a double line as its left border.

示例:

| Col1 | Col2 || Col3 (w/ Double Left Border) |

谢谢你, 本

推荐答案

这取决于您希望在何处使用此双线.对于DataGridCell,垂直网格线绘制在OnRender中,对于DataGridCellsPresenter,水平网格线绘制在OnRender中.但是,DataGridColumnHeader的边界更加复杂.这是在DataGridHeaderBorder的RenderTheme方法中绘制的矩形,我认为没有直接更改整个DataGridColumnHeader的宽度即可更改其宽度的直接方法.此外,标题的边框厚度是DataGrid中以"1px对2px"开头的单元格的厚度的两倍,这是因为标题在两侧都绘制了分隔符.

It depends on where you want this double line. The vertical GridLines is drawn in OnRender for DataGridCell and the horizontal GridLines is drawn in OnRender for DataGridCellsPresenter. The border for the DataGridColumnHeader is more complicated however. It's a Rectangle that's drawn in the RenderTheme method in DataGridHeaderBorder and I don't think that there is a direct way to change its width without re-templating the entire DataGridColumnHeader. Also, the border thickness for the Headers are twice as thick as the Cells in the DataGrid to begin with (1px vs 2px), because the Headers draw their Separators on both sides.

因此,要获得仅影响单元格的双线粗细,可以在希望应用的地方添加特殊的DataGridCell样式.该单元样式所做的全部工作就是向左绘制一个1px的边框,其颜色与GridLines相同.看起来像这样

So, to get double line thickness which just affects the Cells you can add a special DataGridCell style where you want this to apply. All this cellstyle does is to draw a 1px border to the left in the same colour as the GridLines. It'll look something like this

<DataGrid ... HorizontalGridLinesBrush="Black"> <DataGrid.Resources> <Style x:Key="DoubleLeftBorderCell" TargetType="DataGridCell"> <Setter Property="BorderThickness" Value="1,0,0,0"/> <Setter Property="BorderBrush" Value="{Binding ElementName=dataGrid, Path=HorizontalGridLinesBrush}"/> </Style> </DataGrid.Resources> <DataGrid.Columns> <DataGridTextColumn Header="Double left Border" CellStyle="{StaticResource DoubleLeftBorderCell}" Binding="{Binding TextProperty}"/> </DataGrid.Columns> </DataGrid>

没有鼠标悬停效果或要担心的任何问题.但是,如果对DataGridColumnHeader做类似的操作,则会失去排序箭头,鼠标悬停效果,鼠标按下效果等.因此,您必须为其创建一个完整的模板

There is no mouseover effect or anything on the cells to worry about. If you do something similar for a DataGridColumnHeader however, you'll lose the sorting arrows, mouseover effect, mousedown effect etc. so a you'll have to create an entire template for it

更多推荐

仅一栏的特殊网格线样式

本文发布于:2023-10-14 19:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1491923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   样式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!