Silverlight 5 Beta - WebBrowser Control In Browser to Display HTML

In this post, we will see how to use WebBrowser control to display HTML contents in browser using Silverlight 5 beta. In Silverlight 4, we can use the WebBrowser control only in 'Out-Of-Browser' applications.

In Silverlight 5 Beta, now we can use WebBrowser control in the Browser (IE). For this, you will have to first configure the Silverlight application to run in-browser with evaluated trust. WebBrowser control is used for reusing the HTML or ASP.NET contents as well as to integrate external websites in our Silverlight application.

To start with this demonstration, let's first create a Silverlight application with the name 'SL5HTMLCotentsInBrowser' and choose ‘Silverlight 5’ as shown below -

Silverlight WebBrowser Project

Now let's design our MainPage.xaml as shown below. Replace the <Grid></Grid> with the following code -

image

In the above code, I have set the Height and Width of the Grid and main page to 600 and 1000 respectively.

Now let's design the HTML page and put some content as shown below -

image

This page is saved by the name - ''SiteInformation.hml' under 'ClientBin\HTML' folder. Now let's apply settings to make our WebBrowser control to work as an in-browser control to display the HTML or ASP.NET contents.

To run the application in a browser with evaluated trust, you will have to configure the application as below -
  1. Change the registry entry to run evaluated trust application in browser.
  2. Configure the application to run 'Out-Of-Browser'. Also make your application to run in Evaluated Trust.
  3. Sign the .XAP file with a test certificate.
  4. Deploy the certificate in 'Trusted Publisher' and 'Trusted Root Certification Authorities'.
All the above steps are explained in depth in my article ' Silverlight 5 Beta - Run Elevated Trust Applications in Browser' on http://www.dotnetcurry.com/.

Once you complete the configuration of the application, let's hit 'F5' to run the application. You will see the HTML page contents within the browser. Now click on the link to see the external sites within the WebBrowser control. The output will be as shown below -

Silverlight 5 WebBrowser
Silverlight 5 WebBrowser




1 comment:

Unknown said...

can you please suggest me the way to print web browser control page in silverlight
thanks,
neha