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?
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.