Orion31
Orion31

Reputation: 596

TextBlock Run Background Span Whole Line

Is it possible to make a run span the entire width of a TextBlock so the background looks natural and not just on the text of the run?

Current Result: The Background only spans the length of the text.

Expected Result: The Background spans the entire textbox.

Another issue with the first image is that there are (unwanted) white lines between certain Runs (in this case "test" and "1"). My current code is:

Run r = new Run("You: " + SendMessageBox.Text + "\n");
r.Background = Brushes.LightBlue;
ChatHistory.Inlines.Add(r);

Upvotes: 0

Views: 202

Answers (1)

mm8
mm8

Reputation: 169160

Is it possible to make a run span the entire width of a TextBlock so the background looks natural and not just on the text of the run?

No, you should add another TextBlock element for each line:

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

ChatHistory could for example be a StackPanel:

Upvotes: 1

Related Questions