I have a WinForms application, running on .net 3.5. This Application generates HTML on the fly, which includes the complete document, and also an inline-CSS-Stylesheet (inside the head element).
我有一个WinForms应用程序,在.net 3.5上运行。此应用程序动态生成HTML,其中包括完整的文档,以及内联CSS样式表(在head元素内)。
I am using the WebBrowser control and setting browser.DocumentText to my generated HTML, but that does not seem to properly apply styles on the body element (I've set background-color to #000000 in the CSS, but the background is still white).
我正在使用WebBrowser控件并将browser.DocumentText设置为我生成的HTML,但这似乎没有在body元素上正确应用样式(我在CSS中将background-color设置为#000000,但背景仍为白色)。
I wonder if a) there are some alternatives to render relatively simple HTML in C# (i.e. a completely managed HTML renderer) or b) what would be the best way to render HTML using the WebBrowser control, including correct handling of inline-css and without using a temporary file on the hard drive.
我想知道a)是否有一些替代方法可以在C#中呈现相对简单的HTML(即完全托管的HTML呈现器)或b)使用WebBrowser控件呈现HTML的最佳方式,包括正确处理inline-css和不使用使用硬盘上的临时文件。
Edit: The CSS-not-applying issue was a separate problem. I've put my actual CSS in a CDATA block, which seems to cause it not to apply correctly. That is now fixed, but the question itself still stands.
编辑:CSS-not-applied问题是一个单独的问题。我把我的实际CSS放在CDATA块中,这似乎导致它无法正确应用。现在已经修复了,但问题本身仍然存在。
4 个解决方案
#2
3
Stayed with the built-in WebBrowser. The HtmlRenderer from the other answer is great, but renders an image.
坚持使用内置的WebBrowser。另一个答案中的HtmlRenderer非常棒,但渲染图像。
#3
0
Your could look into using a view engine. Most view engines can work in a stand-alone api manner
您可以考虑使用视图引擎。大多数视图引擎可以以独立的api方式工作
for example NHaml and nvelocity both can be used stand alone
例如,NHaml和nvelocity都可以单独使用
http://code.google.com/p/nhaml/
http://code.google.com/p/nhaml/
http://www.castleproject.org/others/nvelocity/index.html
http://www.castleproject.org/others/nvelocity/index.html
And i assume Spark can be as well
我认为Spark也可以
http://dev.dejardin.org/
#4
0
I have developed what you were asking for: a "completely managed HTML renderer", which will "render relatively simple HTML in C#". It supports a subset of CSS, which you can "specify in a inline CSS stylesheet (inside the head element)".
我开发了你要求的东西:一个“完全托管的HTML渲染器”,它将“在C#中呈现相对简单的HTML”。它支持CSS的一个子集,您可以“在内联CSS样式表中指定(在head元素内)”。
For details, see the ModelText HTML control.
有关详细信息,请参阅ModelText HTML控件。
#1
#2
3
Stayed with the built-in WebBrowser. The HtmlRenderer from the other answer is great, but renders an image.
坚持使用内置的WebBrowser。另一个答案中的HtmlRenderer非常棒,但渲染图像。
#3
0
Your could look into using a view engine. Most view engines can work in a stand-alone api manner
您可以考虑使用视图引擎。大多数视图引擎可以以独立的api方式工作
for example NHaml and nvelocity both can be used stand alone
例如,NHaml和nvelocity都可以单独使用
http://code.google.com/p/nhaml/
http://code.google.com/p/nhaml/
http://www.castleproject.org/others/nvelocity/index.html
http://www.castleproject.org/others/nvelocity/index.html
And i assume Spark can be as well
我认为Spark也可以
http://dev.dejardin.org/
#4
0
I have developed what you were asking for: a "completely managed HTML renderer", which will "render relatively simple HTML in C#". It supports a subset of CSS, which you can "specify in a inline CSS stylesheet (inside the head element)".
我开发了你要求的东西:一个“完全托管的HTML渲染器”,它将“在C#中呈现相对简单的HTML”。它支持CSS的一个子集,您可以“在内联CSS样式表中指定(在head元素内)”。
For details, see the ModelText HTML control.
有关详细信息,请参阅ModelText HTML控件。