我想将richTextBox2.Document 附加到richTextBox1,但WPF 不支持联合2 FlowDocument。有什么办法吗?非常感谢!
问问题
1397 次
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 回答