Jonathan Allen
Jonathan Allen

Reputation: 70317

How do I create a vertical text block without using an ItemsControl?

Alright, trying this again. All I want is to rotate a text block, nothing tricky. And I don't want to do it using an ItemsControl because it will require using a control for each and every letter, which is way too expensive for my needs.

enter image description here

Upvotes: 0

Views: 354

Answers (2)

paparazzo
paparazzo

Reputation: 45096

<TextBlock Width="7" HorizontalAlignment="Left">
        S<LineBreak/>
        t<LineBreak/>
        a<LineBreak/>
        c<LineBreak/>
        k
</TextBlock> 

Upvotes: 0

Clemens
Clemens

Reputation: 128070

Despite the controversy if it's a duplicate or not, there may be a way to achieve vertical text on a very low level, involving a GlyphRun. I haven't tested that in detail, but what i know is, you would have to

  1. create a GlyphRun with the IsSideways property set to true, meaning all character will be rotated 90° counter-clockwise,

  2. get a DrawingContext and push (via PushTransform) a 90° clockwise RotateTransform onto it,

  3. draw the GlyphRun to the DrawingContext.

A simple way to get an appropriate DrawingContext would be to override UIElement.OnRender.

Note: GlyphRun's constructor has 13 arguments, but the last 6 may be null :-)

Upvotes: 2

Related Questions