Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
How I can Insert HTML Tag into Silverlight page without Web browser control?

My HTML tag is:

HTML
<html><body><iframe src='www.google.com' /></body></html>
Posted
Updated 26-Feb-12 6:51am
v3
Comments
Ed Nutting 26-Feb-12 13:35pm    
Other than having used single quotes (') rather than double quotes (") for the src attribute, what is your problem here? Have you had an error occur? If so what? Or does it jsut not display the iFrame?

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.
 
Share this answer
 
As the follow up, here is the source code sample, you can insert an <iframe> tag in your aspx or html page:

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


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

C#
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"); 
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900