OmniOwl
OmniOwl

Reputation: 5709

Render HTML tags in C#

Is there an easy-to-use library or otherwise method in which I can pass HTML as a string (with tags like < table > or < div > etc) and then the application will show it correctly on the screen?

So far I have only found HTML Agility Pack, but it doesn't seem very noob friendly.

An Example:

submitted by <a href="http://www.reddit.com/user/kiransran"> kiransran </a> 
to <a href="http://www.reddit.com/r/news/"> news</a> 
<br/> 
<a href="http://imgur.com/GtDN6rz">[link]</a> 
<a href="http://www.reddit.com/r/news/comments/1cretq/infrared_image_of_boston_marathon_suspect_hiding/">[976 comments]</a>

It's from an RSS Feed. I need to show the result in WPF

Upvotes: 0

Views: 2048

Answers (3)

Bauss
Bauss

Reputation: 2797

Take a look at Geckofx:

http://code.google.com/p/geckofx/

However if you want you can use the Webbrowser control, but remember that is just IE.

Upvotes: 0

John Koerner
John Koerner

Reputation: 38087

If you just want to render it, use the web browser control:

<WebBrowser HorizontalAlignment="Left" Height="203" VerticalAlignment="Top" Width="335" Margin="46,52,0,0" Name="wb1"/>

Then call the NavigateToString method:

string s = @"<html><body>Hello <b>World</b></body></html>";
wb1.NavigateToString(s);

Upvotes: 1

MatthewMartin
MatthewMartin

Reputation: 33183

Use string manipulations to extract the html of interest start & finish, wrap it and display it with a browser control:

http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/webbrowser-control-in-wpf/

The string manipulation API is something that you are going to learn anyhow, and if you just want to display the HTML, then you just need to provide the browser control with the suitable html.

You may need a WebRequest to fetch the RSS in the first place, but you haven't asked about that.

Upvotes: 0

Related Questions