我正在尝试在 WPF 中制作自定义 gridview 但我刚刚意识到链接 说:
GridViewHeaderRowPresenter 类
执行列标题的布局
在 GridView 中并放置一个附加的
列标题末尾添加空格
,并且由于末尾有附加列标题,因此最后一列的右侧有一个额外的列。所以我想知道是否可以修改它,请参考下面的图片
我的问题是:
- 我是否可以从网格中删除“A”部分?
- 无论如何,我可以将“B”部分(角色=填充标题)的相同效果添加到“C”部分(第一列之前)吗?
谢谢
I'm trying to make a custom gridview in WPF but I just realized that as this link says:
The GridViewHeaderRowPresenter class
performs layout for the column headers
in a GridView and places an additional
column header at the end to add space
and because of the additional column header at the end, there's an extra column to the right of the last column. so I was wondering if I can modify it, please refer to this image below
My questions are:
- Is there anyway I can remove the 'A' part from the grid?
- Is there anyway I can add the same effect of 'B' part (the role = padding header) to the 'C' Part (before the first column)?
Thanks
发布评论
评论(2)
经过一番摸索后,我设法通过在几个地方设置负边距来隐藏这个额外的列。这虽然很老套,但很有效:
也许还可以添加
GridViewColumnHeader 样式。
第一个似乎可以根据需要设置为负值;当它不能再减少时,它就会达到上限。这样做仍然会在标题的右侧留下一个 2px 的间隙,这是第二种样式修复的。
唉,-2 边距适用于所有 GridViewColumnHeaders(并且样式触发器方法似乎不起作用),因此它可能会稍微扰乱内部边框和内容对齐,但如果可以忍受,则效果很好。
编辑:实际上是的,划伤-2边距,它有太多负面影响。
在
"0,0,-2,0"
,您将获得相同的效果,但没有任何缺点。After poking around a lot I managed to hide this extra column just by setting negative margin in a few places. It's quite hacky but it works:
And perhaps add
in the GridViewColumnHeader style, as well.
First one can be set as negative as you like, it seems; it caps when it can't reduce anymore. Doing so will still leave a wee 2px gap on the right side of the headers, which the 2nd Style fixes.
Alas, the -2 margin applies to all GridViewColumnHeaders (and the Style Trigger method doesn't seem to work), so it can mess with inner borders and content alignment a bit, but if that's tolerable this works fine.
EDIT: Actually yeah scratch the -2 margin, it has too many negative side effects.
Inside
<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}">
you'll find a<GridViewHeaderRowPresenter>
; set its Margin equal to"0,0,-2,0"
and you'll get the same effect without the drawbacks.要删除第一列“C”,您可以将以下属性添加到 DataGrid 定义中:
To get rid of the first column "C" you can add the following property to your DataGrid definition: