修复 WPF DataGrid 列标题被切断的问题?
在我的 WPF 应用程序中,我使用 DataGrid,当我的列的标题标签文本接近列的宽度时,列标题文本的右侧部分会被标题右侧的空白区域截断区域,就像标题右侧的内部填充,宽度为 6 或 8 像素,这似乎没有充分的理由。
我搜索了类似的问题,看到有人提到了无法更改的 0,6, 0,6 填充值,但我不知道他们是否在谈论我所看到的同一件事。
不管怎样,我希望有人知道解决方法,让我知道它是什么。
谢谢!
In my WPF app I use a DataGrid, and when I have columns whose header label text is close to the width of the column, the right part of the column header text gets cut off by a region of blankness on the right side of the header area, which is like internal padding just on the right side of the header that is 6 or 8 pixels wide, which seems to have no good reason.
I searched around for similar questions and saw someone mentioning a 0,6, 0,6 padding value that cannot be changed, but I don't know if they were talking about the same thing I am seeing.
Anyway, I would love for someone who knows a workaround to let me know what it is.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 .NET 4 中,
DataGridColumnHeader
将标头内容包装在DataGridHeaderBorder
的实例中。如果当前设置了Padding
属性,则DataGridHeaderBorder
确实会在内容周围添加"3,3,3,3"
的填充到“0,0,0,0”
。根据
DataGridHeaderBorder
是否用于列标题或行标题,还有其他逻辑。此外,各个主题具有相似但不完全相同的逻辑。阻止 DataGridHeaderBorder 添加其填充的唯一方法是指定您自己的填充。因此您可以使用:
或除全零以外的任何内容,例如
"0.0001"
或"-1"
。DataGridColumnHeader
会将其填充传递给DataGridColumnHeader
,这就是您可以使用上面的隐式样式的原因。In .NET 4, the
DataGridColumnHeader
wraps the header content in an instance ofDataGridHeaderBorder
. TheDataGridHeaderBorder
does appear to add a padding of"3,3,3,3"
around the content, if it'sPadding
property is currently set to"0,0,0,0"
.There is additional logic based on whether the
DataGridHeaderBorder
is being used for the column or row headers. In addition, the various themes have similar, but not exactly the same, logic.The only way to prevent
DataGridHeaderBorder
from adding it's padding is to specify your own. So you can use:Or anything other than all zeros, such as
"0.0001"
or"-1"
. TheDataGridColumnHeader
will pass it's padding on to theDataGridColumnHeader
, which is why you can use the implicit style above.