WPF RichTextBox添加一条有颜色的记录

 

直接上代码,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);
}

posted @ 2015-06-24 14:23  jesse_xie  阅读(520)  评论(0编辑  收藏  举报