如何在RichTextBox WPF C#中获取字符串中单词的颜色?

时间:2019-06-26 06:12:22

标签: c# .net wpf richtextbox

我的RichTextBox中有一个文本,我想检查是否有任何单词不是黑色的。如果没有,那么我想要颜色值。

这是我尝试阅读每个单词的方法,但是我不知道该怎么做才能获得颜色。

Regex regex = new Regex(@"\b[\s,\.-:;]*");
string richText = new TextRange(RichTextBoxData.Document.ContentStart, RichTextBoxData.Document.ContentEnd).Text;
List<string> listofWords = regex.Split(richText).Where(x => !string.IsNullOrEmpty(x)).ToList();
//TextRange textRange = new TextRange(RichTextBoxData.Document.ContentStart, RichTextBoxData.Document.ContentEnd);
if (!String.IsNullOrEmpty(richText))
{
    foreach (string words in listofWords)
    {
        //Check colour
    }
}

0 个答案:

没有答案