XAML Tip: Adding a Line Break to a TextBlock

I'm just starting to mess with XAML as I'm looking to see what I can do with it. As I come across some pretty basic tasks that I'm struggling with, I'll post about it in case any other newbies run into the same issue. One of my first tasks was to create some text on a canvas. However, I couldn't figure out how to do a line break. After searching Live and Google in an attempt to find something, I finally did (on page 3 of each engine). There is an object called <LineBreak/> that will perform a line break in your text. For example:

<TextBlock Margin="5,5,5,5">This is line 1.<LineBreak/>This is line 2.</TextBlock>

Published Monday, April 07, 2008 4:50 PM by Jason N. Gaylord

Comments

# re: XAML Tip: Adding a Line Break to a TextBlock

Tuesday, April 08, 2008 4:04 PM by Bob

Thanks for the tip!

# re: XAML Tip: Adding a Line Break to a TextBlock

Wednesday, April 16, 2008 11:31 PM by Maslarm

<LineBreak/> doesn't work in used Response.Write(xmlDoc.OuterXml);

# re: XAML Tip: Adding a Line Break to a TextBlock

Thursday, July 17, 2008 3:23 PM by Ed

Does this work if you want to bound the text to a resource (i.e. localization)?

# re: XAML Tip: Adding a Line Break to a TextBlock

Wednesday, September 22, 2010 12:00 AM by Jesse

Now your posts shows up first! Very useful

# re: XAML Tip: Adding a Line Break to a TextBlock

Sunday, September 26, 2010 1:23 PM by Tore Aurstad

Great tip Jason, needed it.

- cheers.

-= Random Norwegian WPF Dude =-

# re: XAML Tip: Adding a Line Break to a TextBlock

Friday, April 08, 2011 5:39 PM by Esteban

Great Idea to put this!!!So easy and so difficult to find!

# re: XAML Tip: Adding a Line Break to a TextBlock

Friday, April 29, 2011 5:06 PM by Frylock

This was really helpful.  Thank you.

# re: XAML Tip: Adding a Line Break to a TextBlock

Saturday, July 02, 2011 6:40 AM by avrashow

If you are using a string in quote marks, use &#10;

<Label Content="Type here and&#10;this is line2" ... />

# re: XAML Tip: Adding a Line Break to a TextBlock

Thursday, February 23, 2012 4:36 AM by Alpa

   <TextBlock Margin="0,45,0,208"> This is a simple WPF Browser Based Application(XBAP)....<LineBreak/> line 2</TextBlock>

        <Label Content="Type here and&#10;this is line2" Margin="0,109,0,139" />

       <TextBox Text=" Text box  and&#10;this is line2" Margin="12,176,186,80"></TextBox>

Leave a Comment

(required) 
(required) 
(optional)
(required)