字符串属性中的换行符 [英] Newline in string attribute
问题描述
如何在将文本设置为属性时向文本添加换行符,即:
How can I add a line break to text when it is being set as an attribute i.e.:
<TextBlock Text="Stuff on line1 \n Stuff on line2" />
将其分解为分解格式不是适合我的特定情况的选项.我需要的是某种方式来模拟以下内容:
Breaking it out into the exploded format isn't an option for my particular situation. What I need is some way to emulate the following:
<TextBlock>
<TextBlock.Text>
Stuff on line1 <LineBreak/>
Stuff on line2
</TextBlock.Text>
<TextBlock/>
推荐答案
<TextBlock Text="Stuff on line1
Stuff on line 2"/>
您可以使用任何十六进制编码的值来表示文字.在这种情况下,我使用了换行符(字符 10).如果你想做经典"的vbCrLf
,那么你可以使用

You can use any hexadecimally encoded value to represent a literal. In this case, I used the line feed (char 10). If you want to do "classic" vbCrLf
, then you can use 

顺便说一下,注意语法:它是与号、磅、字母 x,然后是所需字符的十六进制值,最后是分号.
By the way, note the syntax: It's the ampersand, a pound, the letter x, then the hex value of the character you want, and then finally a semi-colon.
另外:为了完整起见,您可以绑定到已经嵌入换行符的文本,就像代码中的常量或在运行时构造的变量一样.
ALSO: For completeness, you can bind to a text that already has the line feeds embedded in it like a constant in your code behind, or a variable constructed at runtime.
这篇关于字符串属性中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!