简体   繁体   中英

Showing pieces of HTML on WPF Form

I'd like to show pieces of HTML on my form. I've looked at a few examples online regarding using a webform or document layout, etc and nothing works for me.

We have a system on our website where a user can enter a notification using a Real Text Editor (CKEditor). The message is saved in the DB and a WPF application on all the computers in the office should display the message.

I would like to support HTML in my WPF program. The HTML isn't in a page, it's a piece of HTML in the db that needs to be displayed in its rendered form on the WPF application.

For example, if someone enters <img src="http://www.google.com/google.jpg" /> it will show the image in the wpf application when I retrieve it from the database and show it on the form.

What's the best way to do this?

PS I can't use a web browser because the Windows has "AllowTranparency" set to true.

Add a WebBrowser control to your application:

<Window x:Class="WpfBrowser.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <WebBrowser Height="311" HorizontalAlignment="Left" Name="webBrowser1" VerticalAlignment="Top" Width="503" />
    </Grid>
</Window>

And then use the NavigateToString of the WebBrowser to load the page from your html string:

webBrowser1.NavigateToString("<html><head></head><body>First row<br>Second row</body></html>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM