Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical Text in Wpf TextBlock

Tags:

c#

wpf

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

like image 637
MarioH Avatar asked Dec 08 '08 15:12

MarioH


1 Answers

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" /> 

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.

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

like image 195
Ray Burns Avatar answered Sep 24 '22 03:09

Ray Burns