【发布时间】:2012-09-26 13:20:43
【问题描述】:
我有一个带有几段的 RichTextBlock。我需要一些段落有背景颜色。我在段落或运行中找不到背景属性。我该怎么做呢?在 WPF 中有一个 Block,但在 WinRT 中似乎不存在。
【问题讨论】:
标签: c# xaml windows-8 microsoft-metro
我有一个带有几段的 RichTextBlock。我需要一些段落有背景颜色。我在段落或运行中找不到背景属性。我该怎么做呢?在 WPF 中有一个 Block,但在 WinRT 中似乎不存在。
【问题讨论】:
标签: c# xaml windows-8 microsoft-metro
这是不可能的,但可以插入带有背景的 StackPanel 的 InlineUIContainer。
【讨论】:
您需要获取段落开头和段落结尾的索引,然后使用:
//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 以获得不错的文本编辑控件。
【讨论】: