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 -
Now let's design our MainPage.xaml as shown below. Replace the <Grid></Grid> with the following code -
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 -
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 -
- Change the registry entry to run evaluated trust application in browser.
- Configure the application to run 'Out-Of-Browser'. Also make your application to run in Evaluated Trust.
- Sign the .XAP file with a test certificate.
- Deploy the certificate in 'Trusted Publisher' and 'Trusted Root Certification Authorities'.
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 -
Will you give this article a +1 ? Thanks in advance