Silverlight 4.0 – WebBrowser Control

Silverlight is still a maturing technology not suitable for every purpose. As such, hybrid applications are often developed where a Silverlight element is embedded in an HTML page. However, this was obviously not an option for out-of-browser Silverlight applications.

The new WebBrowser control allows for an HTML element to be embedded in a Silverlight application when the app is running out-of-browser. This is an important addition for several scenario’s – for example migrating an ASP.NET application to Silverlight can be done in stages as some of the ASP.NET code can be run and accessed from the WebBrowser control.

The WebBrowser control is a relatively simple one and contains the following properties:

  • Source – Gets or sets the URI which is rendered in the WebBrowser control
  • Navigate: – Sets the URI to be loaded in the WebBrowser control (identical to the Source property)
  • NavigateToString: – Displays on-the-fly generated HTML. This can be done using this method.

The syntax for the WebBrowser control is shown below:

<WebBrowser x:Name="DemoBrowser"   Width="1000" Height="800"></WebBrowser>

To set the URI use the following code:

DemoBrowser.Navigate(new Uri("URIstring"));

It is important to note that unless the Silverlight application has elevated trust the WebBrowser will only show HTML from the same domain as the app (a workaround this is to use an iframe to redirect to a page on another domain).

An alternative to the WebBrowser control is the HtmlBrush Control which paints static HTML into objects.

This entry was posted in FAQ and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>