2012-09-26 57 views
2

我有一个有几段的RichTextBlock。我需要一些段落才能有背景颜色。我无法在段落或运行中找到背景属性。我该怎么做呢?在WPF中有一个Block,但它似乎并没有出现在WinRT中。RichTextBlock段落背景颜色

回答

2

这是不可能的,但它可能会插入带有背景的StackPanel的InlineUIContainer。

-1

你需要获得指数为段落的开始和段落的结尾,然后使用:

//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; 

而且你还可以看看ScintillaNET一个不错的文本编辑控制。

+1

我不使用的RichTextBox但RichTextBlock –

+0

所以这是不可能的,你必须除非你创建自己的类,从RichTextBlock再次继承,然后代码整个抽奖部分切换到RichTextBox的.. 。 – Danpe

+1

RichTextBlock是一个密封类。另外,我相信这种妥协可能是一个很好的理由(尽管目前这给我带来很大的痛苦)。 – Sprague