WPF 文本块下划线
我有一个宽度
的文本块
,例如500
,但我的字符串只是说“H”,但我想下划线
整个 textblock
宽度不只是在 H 下面我该怎么办?
I have a textblock
of width
say 500
, but my string is just say "H" but I want to underline
the whole textblock
width not just under H what can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(4)
您应该使用 TextBlock 的属性“TextDecorations”。像这样:
You should use the property "TextDecorations" of the TextBlock. Like that:
只是添加我的 2 美分,通过此代码可以在运行时实现与 Talia 的答案相同的效果:
出于某种原因,VS2010 没有显示 RHS 的 Intellisense,但它可以正确编译和运行。
Just to add my 2 cents, The same effect as Talia's answer can be achieved at runtime through this code:
For some reason VS2010 doesn't show Intellisense for the RHS, but it compiles and runs correctly.
最好的选择可能是使用位于文本块正下方的矩形,其宽度始终是文本块的宽度。像这样:
Your best bet would probably be to use a Rectangle positioned immediately below the text block, whose width is always the width of the text block. Like this: