相关疑难解决方法(0)

WPF标签中的换行符?

如何在WPF中的标签文本中添加换行符,如下所示?

<Label>Lorem 
  ipsum</Label>
Run Code Online (Sandbox Code Playgroud)

wpf label newline

82
推荐指数
3
解决办法
6万
查看次数

WPF Multiline TextBlock LineBreak问题

我有以下代码

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 textblock

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

wpf ×2

label ×1

newline ×1

textblock ×1