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



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: