在 silverlight 应用程序中显示 HTML
我需要在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我这样做的方法是检查应用程序是否在浏览器内运行并相应地更改显示方式。如果在浏览器内运行,我将使用 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
我相信您正在寻找的是 HTML Bridge。
编辑 实际上,我现在不确定如果您运行此 OOB,是否仍然可以访问 javascript。我将进一步研究这一点并进一步更新。我仍然会留下答案以供参考。
第二次编辑这是我发现的。当您在浏览器中运行 silverlight 时,HTML Bridge 将被禁用。这会禁用对 HTML DOM 和 Javascript 的访问。但是,根据 此网站:
请记住,此信息是关于 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:
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.
最近有一个类似问题。
我在那里发布了一个实现的链接,该实现在 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.