Python_Student
Python_Student

Reputation: 137

Displaying HTML code preview in WPF

I want to build a sample application where you can preview HTML code.

For example:

<TabControl......>
    <tabItem Header="HTML".....>
        <!-
            Here I type my HTML code ...
            <html>
                <body>
                    <p>********Some Text*******</p>
                </body>
            </html>
            which would be saved in the database as it is.
        ->
    </TabItem>
    <tabItem Header="Preview".....>
        <!-
             On clicking this Tab the Preview of the
             above HTML code (read from the database)
             should be displayed.
        ->
    </TabItem>
</TabControl>

How do I display the preview?

Upvotes: 0

Views: 1802

Answers (3)

Hooman
Hooman

Reputation: 49

You can Embed the WebBrowser Tools

Upvotes: 0

Access IT
Access IT

Reputation: 95

You can use the WebBrowser control but please do not use it - it is filled with memory leaks and does not dispose propoerly. I have spent lots of time looking for solutions to the problems it produces in production code to no avail.

A quick search on this site will show some of the "unsolved" issues becasue basically it is a wrapper for a COM object (hence unmanaged) version of Internet Explorer and while it seems to work beautifully for displaying an embedded page in WPF the problems far out weigh its appearance of simplicity.

What you can do is use the Microsoft HTML to XAML parser, add a flowdocument tag at the beginning and end of the string and push it into the FlowDocumentScrollViewer control.

Upvotes: 0

Drew Marsh
Drew Marsh

Reputation: 33379

Embed the WebBrowser control on the preview tab and pass the HTML into it using the NavigateToString or NavigateToStream methods.

Upvotes: 2

Related Questions