Display HTML in Silverlight using WebBrowser

Silverlight 4 introduces the WebBrowser control using which you can now display HTML based content in Silverlight.

Note: WebBrowser control only functions in Silverlight Out-Of-Browser applications

Let us see an example. Declare XAML with the following layout

<Grid x:Name="LayoutRoot" Background="White">
<
Grid.RowDefinitions>
<
RowDefinition Height="Auto"/>
<
RowDefinition />
</
Grid.RowDefinitions>

<
StackPanel Height="30" Margin="5" Orientation="Horizontal"
VerticalAlignment="Top" Grid.Row="0">
<
TextBox x:Name="tbUrl" HorizontalAlignment="Left"
Width="300" Margin="5" Text="http://www.devcurry.com" />
<
Button x:Name="btnNav" Content="Click" Margin="5"
Width="40" Click="btnNav_Click" />
</
StackPanel>
<
WebBrowser x:Name="wb" Grid.Row="1" />
</
Grid>

The layout will be similar to the following:

Silverlight WebBrowser

Now code the button event handler

Silverlight WebBrowser

That’s it. Run the application and you can now view HTML content inside the Silverlight plugin

Silverlight WebBrowser






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: