WPF TextBlock文本纵向排列

一.将TextBlock文本纵向排列输出有两种模式。

1.文字正常放置,只是纵向排列。

2.文字同样旋转90度,纵向排列。

二.详见下文实例

1.文本正常放置,纵向排列。

(1)后台代码

string s = text01.Text;
            text01.Text = "";
            int a = s.Length;
            for (int i = 0; i < a; i++) {
                text01.Text += s.Substring(i, 1)+"
";

(2)前台代码

        <TextBlock Name="text01" Text="输入和输出" TextWrapping="Wrap"/>

(3)效果

(4)原理

  每次获取文本的一个字符,然后换行,再获取下一个字符,继续换行,循环到所有字符结束。

 2.文本正常放置,纵向排列的另一种方式。

(1)代码

        <TextBlock Name="text01" TextWrapping="Wrap" Text="输入和输出"  Margin="30,10" FontSize="20" Width="23"/>

(2)效果

(3)原理

  将该TextBlock的宽度设置小一点,然后自动换行,即可实现该功能。

3.文字同样旋转90度,纵向排列。

(1)代码

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Name="text01" Text="输入和输出" TextWrapping="Wrap" Height="25" HorizontalAlignment="Left" FontSize="20" Margin="30,10">
            <TextBlock.LayoutTransform>
                <RotateTransform Angle="90"/>
            </TextBlock.LayoutTransform>
        </TextBlock>
    </Grid>

(2)效果

3.原理:只是使用了一个旋转方法。

原文地址:https://www.cnblogs.com/Khan-Sadas/p/5207382.html