WPF 中 TextBlock 的字母间距(跟踪)?
在 WPF 中使用 TextBlock 进行字母间距(跟踪)的最佳方法是什么?
我认为 TextBlock.Typography 会解决这个问题,但事实并非如此。最好的方法是什么?
What is the best way to do letterspacing (tracking) with TextBlock in WPF?
I would think TextBlock.Typography would have taken care of this but it doesn't. What is the best approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来这个问题并不容易解决。您可以谷歌并找到类似的内容 http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/789c3e1b-e3ae-476f-b37f-d93ef6d0cb7b/(使用字形的方法)。但考虑到 String 是可枚举集合这一事实,有时您可以使用如下标记来解决问题:
调整此标记(面板、模板),您可以获得任何所需的字符串布局。当然,您可以将此标记分离到特殊的用户控件中。
只是作为特定情况的变体。
It seems that this problem cannot be solved easily. You can google and find something like this http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/789c3e1b-e3ae-476f-b37f-d93ef6d0cb7b/ (approach with glyphs). But taking into account the fact that String is enumerable collection sometimes you can solve your problem with markup like this:
Tuning this markup (panels, templates) you can get any desired layout of string. And of course you could separate this markup to a special UserControl.
Just as a variant for particular cases.
我使用了 Kreol 建议的方法,发现这种方法很有效,只是有些字母比其他字母更宽。
当使用 UniformGrid 时,根据定义,每列都具有相同的宽度。这导致字母之间的间距可变。
相反,我使用了水平方向的堆栈面板,并且每个元素都有左边距:
I used the approach suggested by Kreol, and found this to be working except that some letters are wider than others.
When using a UniformGrid every column have same width by definition. This lead to variable spacing between letters.
Instead I used a stackpanel with horizontal orientation, and a left margin on each element: