简体   繁体   English

修复WPF DataGrid列标题被切断的问题?

[英]Fix for WPF DataGrid column headers cut off?

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. 在我的WPF应用程序中,我使用DataGrid,并且当我的列的标题标签文本接近于列的宽度时,列标题文本的右侧部分被标题右侧的空白区域切除。区域,就像标题右侧的内部填充(宽度为6或8像素)一样,似乎没有充分的理由。

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. 我四处搜寻类似的问题,发现有人提到无法更改的0,6,0,6填充值,但我不知道他们是否在谈论我所看到的同一件事。

Anyway, I would love for someone who knows a workaround to let me know what it is. 无论如何,我希望有一个知道解决方法的人让我知道它是什么。

Thanks! 谢谢!

In .NET 4, the DataGridColumnHeader wraps the header content in an instance of DataGridHeaderBorder . 在.NET 4中, DataGridColumnHeader包装在的一个实例的标题内容DataGridHeaderBorder The DataGridHeaderBorder does appear to add a padding of "3,3,3,3" around the content, if it's Padding property is currently set to "0,0,0,0" . 如果DataGridHeaderBorderPadding属性当前设置为"0,0,0,0" ,则确实会在内容周围添加填充"3,3,3,3" "0,0,0,0"

There is additional logic based on whether the DataGridHeaderBorder is being used for the column or row headers. 根据是否将DataGridHeaderBorder用于列标题或行标题,还有其他逻辑。 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. 防止DataGridHeaderBorder添加其填充的唯一方法是指定您自己的填充。 So you can use: 因此,您可以使用:

<Style TargetType="DataGridColumnHeader">
    <Setter Property="Padding" Value="1,0" />
</Style>

Or anything other than all zeros, such as "0.0001" or "-1" . 或除全零以外的任何值,例如"0.0001""-1" The DataGridColumnHeader will pass it's padding on to the DataGridColumnHeader , which is why you can use the implicit style above. DataGridColumnHeader会将其填充传递给DataGridColumnHeader ,这就是为什么您可以使用上面的隐式样式的原因。

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

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