How to put a new line into a wpf TextBlock control?
For completeness: You can also do this:
<TextBlock Text="Line1
Line 2"/>
x0A is the escaped hexadecimal Line Feed. The equivalent of \n
you must use
< SomeObject xml:space="preserve" > once upon a time ...
this line will be below the first one < /SomeObject>
Or if you prefer :
<SomeObject xml:space="preserve" /> once upon a time... this line below < / SomeObject>
watch out : if you both use &10 AND you go to the next line in your text, you'll have TWO empty lines.
here for details : http://msdn.microsoft.com/en-us/library/ms788746.aspx
You can try putting a new line in the data:
<data>Foo bar baz
baz bar</data>
If that does not work you might need to parse the string manually.
If you need direct XAML that's easy by the way:
<TextBlock>
Lorem <LineBreak/>
Ipsum
</TextBlock>
You can also use binding
<TextBlock Text="{Binding MyText}"/>
And set MyText like this:
Public string MyText
{
get{return string.Format("My Text \n Your Text");}
}