I try to create a wpf core application that uses text imported from a ms Access database. Some of the fields are Access Text fields with text set as RTF text but actually they look like html. like this:
10630981 bla bla bla bla bla {bla 25-09}I was thinking to use a FlowDocumentScrollViewer to display this field and a RichTextBox to edit. since I like to work in a MVVM pattern I would need a convertor to convert this 'Html' to a flowdocument and back.
I have been playing for several days no to get this, but did not succeed yet. I feel I am getting near with following Code:
FlowDocument document = new FlowDocument();
string xaml = "<p> The <b> Markup </b> that is to be converted.</p>";
using (MemoryStream msDocument = new MemoryStream((new ASCIIEncoding()).GetBytes(xaml)))
{
TextRange textRange = new TextRange(document.ContentStart, document.ContentEnd);
textRange.Load(msDocument, DataFormats.Xaml);
}
But still I get an exception saying XamlParseException: Cannot create unknown type 'p'.
Can somebody give me a push in the right direction?
`with ``. If you only have simple text then this is simple, but can get quite complex. You should look for a library on NuGet to convert HTML to XAML (or HTML directly to `FlowDocument`. As explained in my answer `TextRange` cannot convert a HTML string to XAML string. You have to do this. Then `TextRange` can display the XAML string using `DataFormats.Xaml`.
– BionicCode Sep 27 '20 at 15:11