WPF Textblock, linebreak in Text attribute

ScottCate picture ScottCate · May 8, 2009 · Viewed 89.3k times · Source

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.

Answer

Paul Alexander picture Paul Alexander · May 8, 2009

Try this:

<TextBlock>
    line1
    <LineBreak />
    line2
</TextBlock>