How to represent Line Break or new line in silverlight textBox

后端 未结 7 1200
逝去的感伤
逝去的感伤 2021-02-01 19:12

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

To represent a LineBreak in Silverlight TextBlock:

use : > line

7条回答
  •  走了就别回头了
    2021-02-01 20:01

    The bottom line at the top

    
    

    Linebreak Weirdness in the Silverlight TextBox

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

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

提交回复
热议问题