如何在silverlight textBox中表示换行或换行 [英] How to represent Line Break or new line in silverlight textBox

查看:30
本文介绍了如何在silverlight textBox中表示换行或换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难匹配 Silverlight 中设置的特殊字符.我只关注以下内容:

I am having hard time to match Special characters set in Silverlight. I only on the following:

在 Silverlight TextBlock 中表示换行符:

To represent a LineBreak in Silverlight TextBlock:

使用:>换行符 <

use : > lineBreak <

但是我用什么来表示 Silverlight TextBox 中的换行符或换行符?

But What do I use to represent a New Line or LineBreak In Silverlight TextBox??

例如:我想要这一行 mag:这是第一行.这是第二行

Example : I want this one line mag : This is line one. This is line two

进入这个:

这是第一行.这是第二行.

This is line one. This is line two.

看来这\r\n 不起作用.这是第一行\r\n

it seems this \r\n is not working. This is line one \r\n

推荐答案

底线在顶

<TextBox Text="This is line one!&#13;This is line two!" />

Silverlight 文本框中的换行异常

如果您要在 Xaml 中以类似于 TextBlock 的方式使用文字文本初始化 TextBox 的内容,那么您需要一种可靠的方式来表示 Silverlight 在 Xaml 中使用的换行符.

If you are going to be initialising content of a TextBox with literal text in Xaml in a similiar way that you might a TextBlock then you need a reliable way to represent the line break character the Silverlight uses in Xaml.

Silveright 使用 CR 字符 (0x0D - ASCII 13) 表示换行符,在 C# 中,您将其作为 \r 包含在字符串文字中.但是 Xaml 不是 C#,因此您不能在 Xaml 中使用 \r.

Silveright uses a CR character (0x0D - ASCII 13) to represent a linebreak which in C# you include in a string literal as \r. However Xaml isn't C# so you can't use \r in Xaml.

Xaml 从根本上说是 XML,但有一些 Xaml 解析奇怪.正如德里克在他的回答中所说的那样,仅在 Xaml 中直接包含换行符在运行时是行不通的(尽管设计者按预期显示了它).您可能认为这是因为 Xml 使用 LF 字符 (0x0A) 作为其换行符.但是,在代码中,您可以将包含\r"或\n"的字符串分配给 Text 属性,并且 TextBox 将显示一个新行.事实上,您可以指定序列\r\n",它会显示一个新行(而不是两个新行).

Xaml is fundementally XML but with some Xaml parsing oddities. Just including a linebreak, as Derek has in his answer, directly in the Xaml will not work at runtime (although the designer displays it as expected). You might think that this because Xml uses the LF character (0x0A) as its linebreak character. However in code you can assign a string containing "\r" or "\n" to the Text property and the TextBox will show a new line. In fact you can assign the sequence "\r\n" and it will show a single new line (not two new lines).

最终,您可以使用 Xml 字符代码实体来表示 Xaml "&#13;" 中的 \r,它在 Xaml 解析过程中幸存下来,原因我实际上无法解释.

Ultimately you can use the Xml character code entity to represent a \r in Xaml "&#13;" which survives the Xaml parsing process for reason which I cannot actually explain.

这篇关于如何在silverlight textBox中表示换行或换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆