2011-01-08 42 views
2

我有以下代碼WPF多行TextBlock的斷行發出

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"); 

的TextBlock顯示:

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

+0

OMG ......它實際上是在VS2010旗艦版中的錯誤。在調整窗口大小之前,有些文字不會顯示...如果有人遇到此問題,請調整窗口大小 – KMC 2011-01-08 11:10:26

回答