Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in Silverlight's textblock

I know that some will reply things such as <LineBreak/> this is not what I'm looking for.

I want to know if I store textblock's string in a resource file, can I do some thing about it to make the text in textblock to go to a new line.

tried "&lt ; LineBreak/ &gt ;" (w/o space),

tried /r/n

tried &#13;&#10;

None of the options worked, anyone got ideas?

like image 612
C_Rance Avatar asked Oct 28 '10 15:10

C_Rance


2 Answers

\r\n should do the trick, I think you had the slashes the wrong way around. Even just \n should work.

In XAML the following works

<TextBlock x:Name="txtMyText" Text="Hello&#10;World"/>

While in the code behind this works

txtMyText.Text = "Hello\nWorld";

For resources, you need to specify xml:space="preserve"

<system:String x:Key="message" xml:space="preserve">Hello&#10;World</system:String>

Using space preserve you can also do the following

<system:String x:Key="message" xml:space="preserve">Hello
World</system:String>

Note, there are no extra spaces because they would show up in the TextBlock because now all white space characters become significant.

like image 131
Chris Taylor Avatar answered Nov 14 '22 20:11

Chris Taylor


Just tried with SL5:

Open Resx file Add a new string. Give it a name (Name column) Enter any value you want (Value column). If you need a linebreak just press SHIFT+ENTER.

In code behind, MyTextBlock.Text=MyResource.MyItem;

Your textblock will correctly show your linebreaks.

like image 2
gkneo Avatar answered Nov 14 '22 20:11

gkneo