1

I have a html string :

<html>
  <body>
    <!-- DTD html gebruiken -->
                    Een host heeft IP adres <span class="ipAdres"><field ref="IpAdres" class="css-class"></field></span>
                    en netmask <span class="ipAdres"><questionParameter ref="NetMask"></questionParameter></span><br></br>
                    Geeft het adres van het <b>netwerk adres</b>:
                    <field ref="NetwerkAdres" CssClass=""><!-- Voor dit veld wordt de default feedback voor een correct antwoord gebruikt--></field><br></br>
                    Geef een ander <b>hostadres</b> binnen hetzelfde netwerk:
                    <field ref="AndereHost" CssClass=""></field><br></br><!-- Voor dit veld worden beide default feedbacks gebruikt-->
                    Geef het broadcast adres binnen dit netwerk:
                    <field ref="BroadcastAdres" CssClass=""></field></body>
</html>

so i want that wpf shows this in a window, but without the tags.. It has to render, but i don't know how i have to do that. Someone who can help me out?

Ruben
  • 55
  • 3
  • 8

4 Answers4

2

You can use the following code to achieve this:

System.Windows.Controls.WebBrowser browser = new System.Windows.Controls.WebBrowser();
browser.NavigateToString(string strHtml);
Joel
  • 4,732
  • 9
  • 39
  • 54
VijayKP
  • 301
  • 1
  • 7
1

Check out this HTML to FlowDocument Converter as the article says "it's not fool proof" though it has worked well enough for me. It allows you to bind directly to a property containing the HTML string and will produce a flow document which can be added to your window.

bstoney
  • 6,594
  • 5
  • 44
  • 51
0

either use WebBrowser control, which would render the html completely, or use RegularExpression to remove everything within < & >

Elad Katz
  • 7,483
  • 5
  • 35
  • 66
  • I use the second option now.. but it's not very nice.. So how do i have to bind the WebBrowser to my viewmodel and so to a string property? – Ruben Mar 31 '11 at 12:30
  • This answer might help with that [databind-the-source-property-of-the-webbrowser-in-wpf](http://stackoverflow.com/questions/263551/databind-the-source-property-of-the-webbrowser-in-wpf/976289#976289) – bstoney Mar 31 '11 at 15:34
0

Have a look at this question it show how to manipulate the html in the webbrowser control. Binding is hardly possible unless you wrap the logic from the post into your viewmodel.

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115