WPF Textblock, linebreak in Text attribute
Is there a way to have \n
make a line break in a TextBlock
?
<TextBlock Text="line1\nLine2" />
Or is there a better way to force a middle line break, inside the Text
attribute?
<LineBreak />
This doesn't work for me, it needs to be the value of the Text
attribute, because the text string is being set from an outside source.
I'm familiar with LineBreak
but it's not the answer I'm looking for.
Try this:
<TextBlock>
line1
<LineBreak />
line2
</TextBlock>
I know this is ressurecting an old question, but I had the same problem. The solution for me was to use HTML encoded line feeds (&#10;
).
Line1&#10;Line2
Looks like
Line1
Line2
For more of the HTML encoded characters check out w3schools
The easiest way is
<TextBlock> blabla <LineBreak /> coucou <LineBreak /> coucou 2 </TextBlock>
So you just write XAML code, and the <LineBreak />
has exactly the same meaning the
in HTML or the "\n" in C#.
<LineBreak/>
http://www.longhorncorner.com/UploadFile/mahesh/XamlLineBreak06092005152257PM/XamlLineBreak.aspx
<LineBreak/> will not work if it is inside a collection such as Grid or StackPanel. In such cases the following would work as shown: