开发者

New line in Silverlight's textblock

开发者 https://www.devze.com 2023-01-22 15:36 出处:网络
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

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?


\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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消