Vertical Text in Wpf TextBlock

后端 未结 14 1738
星月不相逢
星月不相逢 2020-11-29 04:14

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

相关标签:
14条回答
  • 2020-11-29 04:28

    make the text container's max width to allow for one char only and wrap the text:

    <TextBlock TextWrapping="Wrap" MaxWidth="8" TextAlignment="Center" Text="stack" />
    
    0 讨论(0)
  • 2020-11-29 04:31

    create a stackpanel with a bunch ot textblocks that take one char

    0 讨论(0)
  • 2020-11-29 04:33

    Here's a way to insert a '\n' after every character in the text of the TextBlock, that way making it display vertically:

    <TextBlock x:Name="VertTextBlock" Text="Vertical Text" Loaded="VertTextBlock_Loaded"></TextBlock>
    

    Then, in the Loaded event handler, you say:

    TextBlock tb = sender as TextBlock;
    StringBuilder sb = new StringBuilder(tb.Text);
    int len = tb.Text.Length * 2;
    
    for (int i = 1; i < len; i += 2)
    {
        sb.Insert(i, '\n');
    }
    
    tb.Text = sb.ToString();
    

    That solution was proposed by Lette, but I believe my implementation incurs less overhead.

    0 讨论(0)
  • 2020-11-29 04:34

    the accepted answer suggested by Ray Burns does not work for me on .net 4.0. Here is how I did it:

    pull in the mscorlib

    xmlns:s="clr-namespace:System;assembly=mscorlib"
    

    put in your usercontrol/window/page resources

    <s:String x:Key="SortString">Sort</s:String>
    

    and use it like this

    <ItemsControl ItemsSource="{Binding Source={StaticResource SortString}}" Margin="5,-1,0,0"   />    
    

    hope it helps!

    0 讨论(0)
  • 2020-11-29 04:35

    Below XAML code changes the angle of text displayed in a textblock.

    <TextBlock Height="14"
            x:Name="TextBlock1"
            Text="Vertical Bottom to Up" Margin="73,0,115,0" RenderTransformOrigin="0.5,0.5" >
            <TextBlock.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </TextBlock.RenderTransform>
     </TextBlock>
    
    0 讨论(0)
  • 2020-11-29 04:35

    Make an image and fill the block with the image, use photoshop or something designed to manipulate text instead of fiddling in code ?

    0 讨论(0)
提交回复
热议问题