1

richTextBox2.DocumentをrichTextBox1に追加したいのですが、WPFはジョイント2FlowDocumentをサポートしていません。これを行う方法はありますか?どうもありがとうございます!

4

1 に答える 1

3
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;
    }
于 2013-02-28T05:00:00.203 に答える