如何从 WPF TextBlock 中删除额外的填充?
默认情况下,WPF TextBlock
似乎应用了额外的顶部和底部填充。我希望事实并非如此。
我尝试设置负填充,但出现异常:
<块引用>0,-10,0,0' 不是属性“Padding”的有效值。
我尝试设置
LineHeight
属性,但没有明显效果.
这就是 TextBlock 在 Blend 中的外观。我用栗红色标记了有问题的部分。
By default a WPF TextBlock
seems to have additional top and bottom padding applied. I wish this wasn't so.
I've tried setting negative padding, but got an exception:
0,-10,0,0' is not a valid value for property 'Padding'.
I've tried setting the
LineHeight
property, to no apparent effect.
This is how the TextBlock looks in Blend. I've marked the problematic portion with maroon red.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些研究和 HB 引导我找到了正确的答案,即设置以下属性:
Some research and H.B. guided me to the right answer, which is setting the following properties:
这可能是默认情况下
Segoe UI
字体的一部分,例如尝试使用Segoe
。 (您不能分配负填充,但可以分配负边距
,例如:Margin="0,-3,0,0"
)This is probably part of the font which is
Segoe UI
by default, trySegoe
instead for example. (You cannot assign negative padding but you could assign negativeMargins
, e.g.:Margin="0,-3,0,0"
)该空间不是填充,而是字体的一部分,为字符上方和下方的重音符号保留。
接受的答案使行高小于字体高度。
This space is not padding, but part of the font, reserved for accents above and below characters.
The accepted answer makes the line height smaller than the font height.