问题
I have a RichTextBlock with a couple of paragraphs. I need some paragraphs to have a background color. I cannot find the Background property on Paragraph or Run. How do I do this? In WPF there is a Block but it does not seem to be present in WinRT.
回答1:
It is not possible but it is Possible to insert a InlineUIContainer with a StackPanel with a background.
回答2:
You'll need to get the index for the start of the paragraph and for the end of the paragraph and then use:
//Select the line from it's number
int startIndex = richTextBox.GetFirstCharIndexFromLine(lineNumber);
richTextBox.Select(startIndex, length);
//Set the selected text fore and background color
richTextBox.SelectionColor = System.Drawing.Color.White;
richTextBox.SelectionBackColor= System.Drawing.Color.Blue;
And you could also look at ScintillaNET for a nice Text Editing Control.
来源:https://stackoverflow.com/questions/12602717/richtextblock-paragraphs-background-color