简体   繁体   中英

How to append a FlowDocument to RichTextBox?

I want to append richTextBox2.Document to richTextBox1, but WPF dont support to joint 2 FlowDocument. Is any way to do this? Thank you very much!

using System.Text.RegularExpressions;
using System.Windows.Markup;

    richTextBox1.Document = Joint_FlowDocument(richTextBox1.Document, richTextBox2.Document);

    //Joint flowDocument_2 to the end of flowDocument_1
    private FlowDocument Joint_FlowDocument(FlowDocument flowDocument_1, FlowDocument flowDocument_2)
    {
        StringWriter wr_f1 = new StringWriter();
        XamlWriter.Save(flowDocument_1, wr_f1);
        string str_f1 = wr_f1.ToString().Replace("</FlowDocument>", "");
        StringWriter wr_f2 = new StringWriter();
        XamlWriter.Save(flowDocument_2, wr_f2);
        string str_f2 = wr_f2.ToString();
        str_f2 = Regex.Replace(str_f2, "<FlowDocument.*?>", "");
        return XamlReader.Parse(str_f1 + str_f2) as FlowDocument;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM