我想TextBlock's Text在我的代码后面分配并在屏幕上显示它.它也可能包含new line character.但不知何故,TextBlock这不是打印那个角色.我在文本中使用了以下组合来打印新行字符


 \n\r\n有没有人这样做过?你能帮助我吗?
在XAML你可以做这样的
<TextBlock>Hello how are you?<LineBreak/>I'm fine</TextBlock>
Run Code Online (Sandbox Code Playgroud)
在代码中你可以这样做
textBlock.Text = "Hello how are you?\nI'm fine.";
Run Code Online (Sandbox Code Playgroud)
两者都在为我工作.
编辑
对于您的方案,您可以执行此操作
string str = @"Hello how are you?\nI'm fine.";//This is your actual string containing \n as character
Run Code Online (Sandbox Code Playgroud)
或者在你的情况下
string str = _arr[index];
str = str.Replace(@"\n", "\n");
Run Code Online (Sandbox Code Playgroud)
用新行字符替换"\n"字符串.
PS它会在您实际想要显示\n字符串而不是新行字符时产生问题.
| 归档时间: |
|
| 查看次数: |
3040 次 |
| 最近记录: |