Geek Speak – Converting HTML to XAML


Well, I have been playing with Avalon for a bit.  One of the things that I have been playing with is a RSS viewer,  just a little hobby.  Viewing blogs were not difficult, but the displaying of the HTML from the RSS is where the problems start.  But what you really need to do is use a converter and then put it into a FlowDocument.  At the following location you can download a XAML/HTML Converter. http://wpf.netfx3.com/files/folders/developer/entry816.aspx


If you take this code and add it into a class library on it own.  You can then do the following code:


string text = { Some HTML Text };
string xaml = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(text, true);
rssBlogText.Document =
XamlReader.Load(new XmlTextReader(new StringReader(xaml))) as FlowDocument;


This code is part of a UserControl where the Loaded event executes the above code. 
This is the corresponding XAML code:
<
FlowDocumentReader Name=rssBlogText ViewingMode=Scroll
HorizontalContentAlignment=Left IsPageViewEnabled=False IsPrintEnabled=False
IsFindEnabled=False IsScrollViewEnabled=True IsTwoPageViewEnabled=False
Zoom=75
ScrollViewer.CanContentScroll=True
ScrollViewer.VerticalScrollBarVisibility=Disabled ScrollViewer.HorizontalScrollBarVisibility=Disabled/>


This will allow you to see the resulting converted XAML in a FlowDocument.  Try it and let me know.