Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBlock.TextWrapping - how to make the text wrap so that the lines are center-aligned?

In a Windows Phone 7 application, when I place a TextBlock in the grid and set its HorizontalAlignment to "Center" and its TextWrapping to "Wrap", why does the text that overflows the width of the container and is placed on the next line, align with the left side of the otherwise center-aligned block?

Is there any way to setup text wrapping so that all of the text in the text block is center-aligned?

alt text

like image 404
Peter Perháč Avatar asked Oct 20 '10 08:10

Peter Perháč


People also ask

How do you wrap text in WPF?

In WPF, the Label control does not support text wrapping. If you need a label that wraps contents across multiple lines, you can use a TextBlock control. Place a TextBlock control inside a Label and apply wrapping on TextBlock.

How do you wrap text in Python?

Use the wrap() Method in Python One commonly used method is wrap(content, width=length) . Content is the text we need to wrap, and width represents the number of characters per line. The default number of characters is 70 . After wrapping the text, we will use the join() method to join the lines into a single string.

How do you wrap text in idle Python?

Put simply, if you type a very long piece of text, it disappears off the side of the page, unlike this comment box where it wraps the text around into many lines. If you use the return key to wrap the text, instead of starting a new line, it runs the program.


1 Answers

You are probably missing TextAlignment:

<TextBlock TextAlignment="Center" /> 

HorizontalAlignment will center the TextBlock, TextAlignment will align the text inside the textblock.

like image 186
Francesco De Vittori Avatar answered Oct 05 '22 19:10

Francesco De Vittori