The code below actually works as I want - this question a little misleading. Please ignore it.
Normally when I set Text
property of <
Re: "I just hope you are not using this to align your text. There are many other more elegant methods to do so."
Sounds like you might want to use the Padding property: http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.padding(VS.85).aspx.
See also the various alignment & margin properties.
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.
set the xml:space property to preserve in your XAML, i assume you are using WPF
<TextBlock xml:space="preserve" Text=" Hello world! " />
EDIT: It is sometimes easier to do things in XAML. I just hope you are not using this to align your text. There are many other more elegant methods to do so.