Welcome to MSDN Blogs Sign in | Join | Help

David Waddleton's Geek Speak

Find out what Geeks talk about
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.

Posted: Wednesday, July 19, 2006 4:11 PM by David Waddleton
Filed under:

Comments

TrackBack said:

# July 22, 2006 2:05 PM

ASPInsiders said:

I just was at Quiznos hanging out with @QuiznosNick . He's a former Technology Executive who bought a

# April 3, 2009 3:37 AM
New Comments to this post are disabled
Page view tracker