Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Textblock, linebreak in Text attribute

Tags:

wpf

textblock

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.

like image 411
ScottCate Avatar asked May 07 '09 22:05

ScottCate


People also ask

How do I create a line break in TextBlock WPF?

Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.

How do you insert a line break in XAML?

XAML attributes of type String may contain any special characters, as long as those are referenced as hex-codes. For example, a simple line break ( \n ) would be represented as &#x0a; , for \r\n you'd use &#x0d;&#x0a; and so on.

How do you go down a line in C#?

The \n or the \r escape character in Mac is used to add a new line to the console in C#. For a Windows machine, we should use the \n escape character for line breaks.

How do I make a line in WPF?

To draw a line, create a Line element. Use its X1 and Y1 properties to set its start point; and use its X2 and Y2 properties to set its end point. Finally, set its Stroke and StrokeThickness because a line without a stroke is invisible. Setting the Fill element for a line has no effect, because a line has no interior.


1 Answers

Try this:

<TextBlock>     line1     <LineBreak />     line2 </TextBlock> 
like image 135
Paul Alexander Avatar answered Sep 24 '22 20:09

Paul Alexander