RichTextBlock paragraphs background color

坚强是说给别人听的谎言 提交于 2019-12-11 00:48:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!