Wpf TextBlock 中的竖排文本 [英] Vertical Text in Wpf TextBlock

查看:41
本文介绍了Wpf TextBlock 中的竖排文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以垂直显示 TextBlock 中的文本,以便所有字母相互堆叠(不使用 LayoutTransform 旋转)?

Is it possible to display the text in a TextBlock vertically so that all letters are stacked upon each other (not rotated with LayoutTransform)?

推荐答案

还没有人提到使用纯 XAML 垂直堆叠任意字符串的字母(不旋转它们)的明显而微不足道的方法:

Nobody has yet mentioned the obvious and trivial way to stack the letters of an arbitrary string vertically (without rotating them) using pure XAML:

<ItemsControl
  ItemsSource="Text goes here, or you could use a binding to a string" />

这只是通过识别字符串是一个 IEnumerable 的事实来垂直排列文本,因此 ItemsControl 可以将字符串中的每个字符视为一个单独的项目.ItemsControl 的默认面板是 StackPanel,因此字符垂直排列.

This simply lays out the text vertically by recognizing the fact that the string is an IEnumerable and so ItemsControl can treat each character in the string as a separate item. The default panel for ItemsControl is a StackPanel, so the characters are laid out vertically.

注意:为了精确控制水平定位、垂直间距等,可以在 ItemsControl 上设置 ItemContainerStyle 和 ItemTemplate 属性.

Note: For precise control over horizontal positioning, vertical spacing, etc, the ItemContainerStyle and ItemTemplate properties can be set on the ItemsControl.

这篇关于Wpf TextBlock 中的竖排文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆