直接上代码,richTextLog是RichTextBox的Name
private void AppendText(Brush brush, string txt)
{
TextPointer tp = richTextLog.CaretPosition;
Run run = new Run(txt, tp);
TextPointer tp1 = run.ContentStart;
TextPointer tp2 = run.ContentEnd;
//TextPointer tp1 = richTextLog.CaretPosition;
//TextPointer tp2 = richTextLog.Document.ContentEnd;
this.richTextLog.Selection.Select(tp1, tp2);
this.richTextLog.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, brush);
}