WPF Multiline TextBlock LineBreak issues

Posted by KMC on Stack Overflow See other posts from Stack Overflow or by KMC
Published on 2011-01-08T08:36:09Z Indexed on 2011/01/08 10:53 UTC
Read the original article Hit count: 313

Filed under:
|

I have the following code

txtBlock1.Inlines.Add("This is first paragraph \n This is second paragraph");

then TextBlock would display:

This is first paragraph
This is second paragraph

But, if I have the following (which I though is equivalent);

txtBlock1.Inlines.Add("This is first paragraph");
txtBlock1.Inlines.Add("\n");
txtBlock1.Inlines.Add("This is second paragraph");

TextBlock display:

This is first paragraph // but second paragraph missing

If I separate out the linebreak then the rest of text after the linebreak doesn't show. Why?

I have to use run:

Run run1 = new Run();
run1.Text = "First Paragraph";
run1.Text += "\n";
run1.Text += "Second Paragraph";
txtBlock1.Inlines.Add(run1); 

Then it produce the result correctly. Why I cannot add inline text to Textblock and require me to use Run?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about textblock