WPF向richtextbox光标处插入指定文本
private void InsertText(RichTextBox tb, string text)
{
tb.CaretPosition.InsertTextInRun(text);
if (tb.CaretPosition.LogicalDirection == LogicalDirection.Backward)
{
TextPointer tp = tb.CaretPosition.GetPositionAtOffset(text.Length, LogicalDirection.Forward);
if (tp != null)
{
tb.CaretPosition = tp;
}
}
}