【发布时间】:2011-01-08 18:55:50
【问题描述】:
我有以下代码
txtBlock1.Inlines.Add("This is first paragraph \n This is second paragraph");
然后 TextBlock 会显示:
This is first paragraph
This is second paragraph
但是,如果我有以下内容(我认为这是等价的);
txtBlock1.Inlines.Add("This is first paragraph");
txtBlock1.Inlines.Add("\n");
txtBlock1.Inlines.Add("This is second paragraph");
文本块显示:
This is first paragraph // but second paragraph missing
如果我将换行符分开,则换行符后的其余文本不会显示。为什么?
我必须使用运行:
Run run1 = new Run();
run1.Text = "First Paragraph";
run1.Text += "\n";
run1.Text += "Second Paragraph";
txtBlock1.Inlines.Add(run1);
然后它会正确产生结果。为什么我不能将内联文本添加到Textblock 并要求我使用Run?
【问题讨论】:
-
omg...这实际上是 VS2010 Ultimate 中的一个错误。 Sometext 在我调整窗口大小之前不会显示...如果有人碰巧遇到这个,请调整窗口大小