TextBlock运行背景跨度整行

问题描述 投票:0回答:1

是否有可能使跑步跨越TextBlock的整个宽度,因此背景看起来很自然而不仅仅是在跑步的文本上?

目前的结果:The Background only spans the length of the text.

预期成果:The Background spans the entire textbox.

第一张图像的另一个问题是某些Runs(在本例中为“test”和“1”)之间存在(不需要的)白线。我目前的代码是:

Run r = new Run("You: " + SendMessageBox.Text + "\n");
r.Background = Brushes.LightBlue;
ChatHistory.Inlines.Add(r);
c# .net wpf textblock
1个回答
1
投票

是否可以使运行跨越TextBlock的整个宽度,使背景看起来自然而不仅仅是在运行的文本上?

不,你应该为每一行添加另一个TextBlock元素:

TextBlock t = new TextBlock() { Text = "You: " + SendMessageBox.Text };
t.Background = Brushes.LightBlue;
ChatHistory.Children.Add(t);

ChatHistory例如可以是StackPanel

© www.soinside.com 2019 - 2024. All rights reserved.