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

No comments:

Post a Comment