tags:

views:

2149

answers:

4

Is there a way to have \n make a linebreak 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 but it's not the answer I'm looking for.

A: 

<LineBreak/>

http://www.longhorncorner.com/UploadFile/mahesh/XamlLineBreak06092005152257PM/XamlLineBreak.aspx

jcollum
answered before my linebreak isn't he answer; edit.
ScottCate
Scott I don't understand your comment.
jcollum
The problem is that <LineBreak/> doesn't work on Windows XP. It may also have something to do with the .NET version installed. There are no exceptions and no errors other than the visual elements don't display correctly.
Charles
A: 

Try this:

<TextBlock>
    line1
    <Linebreak />
    line2
</TextBlock>
Paul Alexander
answered before my linebreak isn't he answer; edit.
ScottCate
Haven't tried this directly but off the top of my head you could try xml:space="preserve" and then embed the line break in the Text property directly.
Paul Alexander
A: 

How about breaking the line into two tags?

<StackPanel>
    <TextBlock Text="Line1" />
    <TextBlock Text="Line2" />
</StackPanel>
Cameron MacFarland
+4  A: 

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 http://www.w3schools.com/TAGS/ref_ascii.asp

Noaki
Works great. Thanks.
matthew.perron