Let's say I'm crazy and I want to implement an basic HTML rendering engine with c#. I would like to use WPF Controls to display the HTML Layout.
While there is nothing to gain with such an idea, I still want to try it out! So what libraries, projects and documentation would help me get this done?
Since WPF XAML's capabilities are a superset of HTML's capabilities, pretty much all you will need to do is map the one to the other.
If your input is XHTML you can simply use XSLT or LINQ-to-XML to get the data.
If you use XSLT you will end up with a XAML that you parse with XamlReader.Parse() to get a UIElement you can add to your Window or other WPF container. This is probably more work than using LINQ-to-XML because XSLT is relatively limited.
If you use LINQ-to-XML you can choose to produce XAML and then parse it as in the XSLT case, or you can just create the object tree directly. If you create XAML using LINQ-to-XML, I would write the actual translation code in VB.NET instead of C# which is my normal preferred language. VB.NET's "XML Literal" syntax makes that part of the job easier.
If your input is arbitrary HTML and not XHTML, I would use a third party library to convert it to XHTML and work from there. Handling all of HTML's parsing strangeness is a lot of work and probably mostly unrelated to your actual goal.
If you just want to display HTML without turning it into WPF objects, you can use the Frame control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With