在 silverlight 应用程序中显示 HTML

发布于 2024-10-05 14:17:19 字数 189 浏览 1 评论 0原文

我需要在我的 silverlight 应用程序中显示 HTML,但找不到执行此操作的方法。我无法使用 Web 浏览器控件,因为它需要能够在浏览器中或在浏览器外运行。

有谁知道执行此操作的好方法,因为我目前能想到的就是在文本上运行替换方法,以将标签替换为 C# 等效项,例如(
\n)。

I need to display HTML in my silverlight application and cannot find a way of doing it. I cannot use the web browser control as it needs to be able to run in or out of a browser.

Does anyone know of a good way to do this, because all I can think of doing at the moment is running replace methods on the text to just replace the tags with C# equivalents eg(<br /> to \n).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬﹪忆之殇 2024-10-12 14:17:19

我这样做的方法是检查应用程序是否在浏览器内运行并相应地更改显示方式。如果在浏览器内运行,我将使用 IFrame 覆盖应用程序,如本文所述:http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx。否则,我使用 WebBrowser 控件。我有一个控件,可以在我的书随附的源代码中为您完成这一切,可以从 Apress 网站下载:http://www.apress.com/book/downloadfile/4638

希望这有帮助......

克里斯

The way I do it is to check if the application is running inside the browser and change the means of display accordingly. If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/book/downloadfile/4638.

Hope this helps...

Chris

翻身的咸鱼 2024-10-12 14:17:19

我相信您正在寻找的是 HTML Bridge

编辑 实际上,我现在不确定如果您运行此 OOB,是否仍然可以访问 javascript。我将进一步研究这一点并进一步更新。我仍然会留下答案以供参考。

第二次编辑这是我发现的。当您在浏览器中运行 silverlight 时,HTML Bridge 将被禁用。这会禁用对 HTML DOM 和 Javascript 的访问。但是,根据 此网站

首次安装 OOB 应用程序时,HTML Bridge 不可用。但是,如果您修改应用程序安装文件夹中的index.html,只需添加enablehtmlaccess 参数,就可以强制执行此操作。

它有效!

您甚至可以使用 HtmlPage 类的众所周知的方法创建动态 HTML 元素。您甚至可以使用 Navigate() 方法及其“_blank”参数打开一个新的浏览器窗口。

请记住,此信息是关于 SL 3 的。这可能已更改,但我对此表示怀疑。因此,您可能想要做的就是在 SL 应用程序的启动中构建一个脚本,以检测您的应用程序是否在浏览器中运行。如果是,那么您可能需要调用一些脚本来为您修改该文件。

I believe what you are looking for is HTML Bridge.

Edit I'm am actually now unsure if you'll still have access to javascript if you're running this OOB. I'm going to look into this some more and will further update. I'll still leave the answer up though for reference.

Second Edit Here is what I've found. HTML Bridge is disabled when you run silverlight out of browser. This disables access to the HTML DOM as well as Javascript. However, according to a comment on this site:

HTML Bridge is not available when you first install a OOB app. But you CAN force it if you modify the index.html in the folder where the app is installed just adding the enablehtmlaccess parameter.

It works!

You can even create dynamic HTML elements using the well-known methods of the HtmlPage class. You can even open a new browser window with the Navigate() method and its "_blank" parameter.

Keep in mind this information was posted about SL 3. Its possible that this may have changed, but I doubt it. So it seems that what you may want to do is build a script into the startup of your SL app that detects whether or not your app is running out of browser. If it is then you may want to have some script to call that can modify this file for you.

爱本泡沫多脆弱 2024-10-12 14:17:19

最近有一个类似问题

我在那里发布了一个实现的链接,该实现在 Silverlight 中内联解析和显示 HTML。当然,它仅适用于简单的 HTML,但也许您可以根据您的需要扩展它。

There recently was a similar question.

I posted a link there to an implementation that parses and displays HTML inline in Silverlight. Of course, it will work only with simple HTML, but maybe you can expand it to your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文