c# - WPF writing html to a rich text box -
i working on wpf windows application using c# code. application inherited. have limited experience using wpf. have rich text box control used build email using html. there code read rich text box contents , store results html in database. code working. need write reverse writing html rich text box appears text.
below code have read rich text box.
textrange xaml = new textrange(emailbodyrichtextbox.document.contentstart, emailbodyrichtextbox.document.contentend); memorystream ms = new memorystream(); xaml.save(ms, dataformats.xaml); string xamlstring = asciiencoding.default.getstring(ms.toarray()); string html = htmlconverter.htmlfromxamlconverter.convertxamltohtml("<flowdocument>" + xamlstring + "</flowdocument>"); html = httputility.htmlencode(html);
to save richtextbox's content regular string can save in database:
string formattedemail = xamlwriter.save(emailbodyrichtextbox.document); to reload richtextbox string:
emailbodyrichtextbox.document = xamlreader.parse(formattedemail); if want store emails in database , reload them richtextboxes, there no point in converting html, can introduce conversion format mismatches.
Comments
Post a Comment