简体   繁体   English

在WPF表单上显示HTML片段

[英]Showing pieces of HTML on WPF Form

I'd like to show pieces of HTML on my form. 我想在表单上显示HTML部分。 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). 我们的网站上有一个系统,用户可以使用真实文本编辑器(CKEditor)输入通知。 The message is saved in the DB and a WPF application on all the computers in the office should display the message. 消息保存在数据库中,办公室中所有计算机上的WPF应用程序都应显示该消息。

I would like to support HTML in my WPF program. 我想在我的WPF程序中支持HTML。 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. HTML不在页面中,它是db中的一段HTML,需要在WPF应用程序上以其呈现的形式显示。

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. 例如,如果有人输入<img src="http://www.google.com/google.jpg" /> ,当我从数据库中检索并在表单上显示该图像时,它将在wpf应用程序中显示该图像。

What's the best way to do this? 最好的方法是什么?

PS I can't use a web browser because the Windows has "AllowTranparency" set to true. PS我无法使用Web浏览器,因为Windows将“AllowTranparency”设置为true。

Add a WebBrowser control to your application: 将WebBrowser控件添加到您的应用程序:

<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: 然后使用WebBrowserNavigateToString从您的html字符串加载页面:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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