如何在 WPFToolkit DataGrid 的列之间创建间隙
我有一个 WPF 数据网格(来自 WPF 工具包,如标题所示),我想要一些列之间有一个间隙,上面甚至没有标题,您可以看到之间的背景。我不知道如何管理这个。
顺便说一句,我的所有列都是 TemplateColumns,但我更喜欢一个解决方案,其中我不必为每个列设置样式,并且标题的一侧有一个空白。 也许类似于
,但不幸的是,这样的东西并不存在。
I have a WPF Data Grid (From the WPF Toolkit as the title indicates) and I want a gap between some Columns, where not even a header is above and you can see the background between. I don't have any idea how to manage this.
By the way all my Columns are TemplateColumns, but I would prefer a Solution where I don't have to style every single column and it's header to have a gab on one side.
Perhaps something like <DataGridGapColum Width="5" />
, but something like this does not exist unfortunately.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这需要一些步骤。首先,我们需要关闭 DataGrid 中的网格线,以便我们可以获得“间隙单元格”。我们将把 GridLines 留给 DataGridCells。我们还必须指定一个 GridLinesBrush。我们无法为 DataGridColumn 创建“DataGridGapColumn”样式,因为它不是从 FrameworkElement 派生的,因此我们必须满足于 GapCellStyle 和 GapHeaderStyle。然后我们可以创建一个像这样的“DataGridGapColumn”
包含一些列和间隙列的示例
更新
您可以将样式放入 ResourceDictionary 或 Window.Resouces 中。例子
This will require some steps. First we need to turn off the GridLines in the DataGrid so we can get "Gap Cells". We will leave the GridLines to the DataGridCells instead. We also have to specifiy a GridLinesBrush. We can't create a "DataGridGapColumn" Style for a DataGridColumn since it doesn't derive from FrameworkElement so we will have to settle for a GapCellStyle and a GapHeaderStyle. Then we can create a "DataGridGapColumn" like this
Example with some Columns and Gap columns
Update
You could put the Styles in a ResourceDictionary or in Window.Resouces. Example