将HTML框架插入Silverlight页面 [英] Insert HTML Frame into Silverlight page

查看:55
本文介绍了将HTML框架插入Silverlight页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有Web浏览器控件的情况下将HTML标记插入Silverlight页面?

我的HTML标签是:

 <   html  > ;  <   body  >  <   iframe     src   ='  www.google.com'   / >  /body  <  /html  >  

解决方案

Silverlight不支持托管HTML(例如WPF的Frame元素),但不应这样储物柜.还有另一种方法可以实现这一目标.

基础知识是确保Silverlight控件托管在启用了isWindowless参数的情况下,然后您可以在运行时通过HtmlPage类创建IFRAME元素并将src属性设置为HTML页面位置.


<后续,这是源代码示例,您可以插入< iframe>在您的aspx或html页面中标记:

 <   iframe     id   ="    样式  ="  >  



然后,您可以使用HTML-DOM桥从Silverlight代码中使用此对象:

 System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById(" );
如果(myFrame!= )
{
     myFrame.SetStyleAttribute(" "  1024");
     myFrame.SetStyleAttribute(" "  768");
     myFrame.SetAttribute(" ,txtURI.Text);
     myFrame.SetStyleAttribute(" "  0");
     myFrame.SetStyleAttribute(" "  50");
     myFrame.SetStyleAttribute(" " 可见");
} 


How I can Insert HTML Tag into Silverlight page without Web browser control?

My HTML tag is:

<html><body><iframe src='www.google.com' /></body></html>

解决方案

Silverlight does not support hosting HTML (like WPF''s Frame element) but that should not be a blocker. There''s another way to achieve this.

The basics are to make sure the Silverlight control is hosted with the isWindowless parameter enabled and then you can at runtime through the HtmlPage class create an IFRAME element and set the src attribute to the HTML page location.


As the follow up, here is the source code sample, you can insert an <iframe> tag in your aspx or html page:

<iframe id="ifHtmlContent" style="position:absolute"/>



Then you can use this object from your Silverlight code using the HTML-DOM bridge:

System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null) 
{
     myFrame.SetStyleAttribute("width", "1024");
     myFrame.SetStyleAttribute("height", "768");
     myFrame.SetAttribute("src", txtURI.Text);
     myFrame.SetStyleAttribute("left", "0");
     myFrame.SetStyleAttribute("top", "50");
     myFrame.SetStyleAttribute("visibility", "visible"); 
} 


这篇关于将HTML框架插入Silverlight页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆