开发者

Displaying HTML code preview in WPF

开发者 https://www.devze.com 2022-12-09 08:27 出处:网络
I want to build a sample application where you can preview HTML code. For example: <TabControl......>

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 开发者_JAVA技巧of the
             above HTML code (read from the database)
             should be displayed.
        ->
    </TabItem>
</TabControl>

How do I display the preview?


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


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.


You can Embed the WebBrowser Tools

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号