我有以下代码
txtBlock1.Inlines.Add("This is first paragraph \n This is second paragraph");
Run Code Online (Sandbox Code Playgroud)
然后TextBlock将显示:
This is first paragraph
This is second paragraph
Run Code Online (Sandbox Code Playgroud)
但是,如果我有以下(我虽然相同);
txtBlock1.Inlines.Add("This is first paragraph");
txtBlock1.Inlines.Add("\n");
txtBlock1.Inlines.Add("This is second paragraph");
Run Code Online (Sandbox Code Playgroud)
TextBlock显示:
This is first paragraph // but second paragraph missing
Run Code Online (Sandbox Code Playgroud)
如果我将换行分开,则换行后的其余文本不会显示.为什么?
我必须使用run:
Run run1 = new Run();
run1.Text = "First Paragraph";
run1.Text += "\n";
run1.Text += "Second Paragraph";
txtBlock1.Inlines.Add(run1);
Run Code Online (Sandbox Code Playgroud)
然后它正确地产生结果.为什么我无法添加内联文本Textblock并要求我使用Run?
看到这个答案:在WPF文本块中获取段落的最佳方法是什么?(换行符?)
你需要:
txtBlock1.Inlines.Add("This is first paragraph");
txtBlock1.Inlines.Add(new LineBreak());
txtBlock1.Inlines.Add("This is second paragraph");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10381 次 |
| 最近记录: |