简体   繁体   English

Silverlight文本块中的新行

[英]New line in Silverlight's textblock

I know that some will reply things such as <LineBreak/> this is not what I'm looking for. 我知道有些人会回复诸如<LineBreak/>这样的事情,这不是我想要的。

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. 我想知道如果我将textblock的字符串存储在资源文件中,我可以做些什么来使textblock中的文本转到新行。

tried "&lt ; LineBreak/ &gt ;" 试过"&lt ; LineBreak/ &gt ;" (w/o space), (没有空间),

tried /r/n 试过/r/n

tried &#13;&#10; 试过&#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. \\r\\n应该做的伎俩,我认为你有一个错误的斜线。 Even just \\n should work. 即使只是\\n应该工作。

In XAML the following works 在XAML中,以下工作

<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" 对于资源,您需要指定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. 请注意,没有多余的空格,因为它们会显示在TextBlock因为现在所有空白字符都变得很重要。

Just tried with SL5: 刚试过SL5:

Open Resx file Add a new string. 打开Resx文件添加新字符串。 Give it a name (Name column) Enter any value you want (Value column). 为其命名(名称列)输入您想要的任何值(值列)。 If you need a linebreak just press SHIFT+ENTER. 如果您需要换行,只需按SHIFT + ENTER。

In code behind, MyTextBlock.Text=MyResource.MyItem; 在后面的代码中,MyTextBlock.Text = MyResource.MyItem;

Your textblock will correctly show your linebreaks. 您的文本块将正确显示您的换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM