Eitan
Eitan

Reputation: 1494

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?

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

Upvotes: 6

Views: 12063

Answers (1)

Răzvan Flavius Panda
Răzvan Flavius Panda

Reputation: 22116

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>");

Upvotes: 7

Related Questions