一佳一

记录像1+1一样简洁的代码

导航

wpf richtextbox 插入新添加内容添加到头部

Posted on 2022-02-11 14:20  一佳一  阅读(495)  评论(0编辑  收藏  举报
public void AppendTextToHead(string text)
        {
            TextRange textRange = new TextRange(txtRich.Document.ContentStart, txtRich.Document.ContentEnd);
            //把之前的文本追加到新内容后面
            string value = text + "\r" + textRange.Text;
            Paragraph p = new Paragraph();
            p.Inlines.Add(new Run(value));
            txtRich.Document.Blocks.Clear();
            txtRich.Document.Blocks.Add(p);
        }

代码如上,其他语言也可以用这个逻辑,比如Web的 

 $("#opinfo").html(szTip + $("#opinfo").html());