Set TextBlock to preserve white space at the beginning and at the end?

Rasto picture Rasto · May 9, 2011 · Viewed 17.3k times · Source

EDIT:

The code below actually works as I want - this question a little misleading. Please ignore it.


Normally when I set Text property of TextBlock like this:

TextBlock tb = new TextBlock();
tb.Text = "     Hello World ";

The whitespace at the beginning and at the end of text are not shown. The text shown by TextBlock is only Hello World. How can I set TextBlock to display them (i.e., not remove the whitespace)? Am I missing some property?

Answer

Danield picture Danield · Aug 25, 2011

In this case you don't need to use xml:space="preserve"

<TextBlock xml:space="preserve" Text="     Hello world!    " />

WILL display the whitespaces, however

<TextBlock>    Hello world!    </TextBlock>

won't.