简体   繁体   English

如何在后面的代码中创建HTML文档并将其加载到WPF浏览器中

[英]How do I create an HTML document in my code behind and load it into a WPF browser

I have a C# WPF application. 我有一个C#WPF应用程序。 In my UI I have a WebBrowser that is collapsed and will remain collapsed at all times. 在我的UI中,我有一个折叠的WebBrowser ,并将始终保持折叠状态。 In my code behind I want to create an HTML document and load this document into the collapsed WebBrowser . 在后面的代码中,我想创建一个HTML文档并将该文档加载到折叠的WebBrowser

The only thing I can think of is writing my HTML as a string and then using File.Create() to create file and then using Browser.Navigate to navigate to that file. 我唯一想到的就是将HTML编写为字符串,然后使用File.Create()创建文件,然后使用Browser.Navigate导航到该文件。

The problem is though, I don't want to create any temp files on the computer or have to reference any file paths. 但问题是,我不想在计算机上创建任何临时文件,也不必引用任何文件路径。 Is there any way to create some kind of HTML file object in memory and then pass this object to the WebBrowser to be loaded? 有什么方法可以在内存中创建某种HTML文件对象,然后将该对象传递给WebBrowser进行加载?

You can use NavigateToString or NavigateToStream methods of WebBrowser control. 您可以使用WebBrowser控件的NavigateToString或NavigateToStream方法。

I suggest to you, Use navigateToString method. 我建议您,使用navigationToString方法。 Just pass html text to method. 只需将html文本传递给方法即可。

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

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