Reader Level:

Windows Phone WebBrowser

By Raj Kumar Beniwal on Mar 02, 2011
This article describes the use of the Windows Phone WebBrowser control.
  • 0
  • 0
  • 9232

This article describes the use of the Windows Phone WebBrowser control. WebBrowser is like a mini browser which displays web content, static web content, dynamically generated web content from the network.


Getting Started

Creating a Windows Phone Application:

  1. Open Visual Studio 2010.
  2. Go to File => New => Project
  3. Select Silverlight for Windows Phone from the Installed templates and choose Windows Phone Application
  4. Enter the Name and choose the location.

Click OK. 


Image 1.

Now drag and drop a TextBox, Button and WebBrowser control on page. You can set the properties manually.

<!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <TextBox Height="78" Text="" HorizontalAlignment="Left" Margin="0,15,0,0" Name="textBlock1" VerticalAlignment="Top" Width="383" />

            <Button Content="Go" Height="72" HorizontalAlignment="Left" Margin="362,18,0,0" Name="button1" VerticalAlignment="Top" Width="107" Click="button1_Click" />

            <phone:WebBrowser HorizontalAlignment="Left" Margin="12,99,0,0" Name="webBrowser1" VerticalAlignment="Top" Width="438" Height="488" BorderThickness="1" Background="{StaticResource PhoneBackgroundBrush}" >


                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                                <GradientStop Color="Black" Offset="0"/>

                                <GradientStop Color="White" Offset="1"/>




                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                                <GradientStop Color="Black" Offset="0"/>

                                <GradientStop Color="#FF7E2C2C" Offset="1"/>






Code Behind.

private void button1_Click(object sender, RoutedEventArgs e)


            string str = textBlock1.Text;

            webBrowser1.Navigate(new Uri(str, UriKind.Absolute));           



Now build and run the application. 

If we type wrong website url like this. Then it gives error.


Image 2.


Image 3.

When we enter website url in the proper format, it shows output like this.


Image 4.

Question or comments are most welcome. 

Article Extensions
Contents added by masi boo on Jun 07, 2011
I exactly copy-pasted ur code, but it only shows me white box looks like ur article Image 2. I might doing something wrong. Could you throw some light? compete solution is uploaded. Thanks in advance. 
Raj Kumar Beniwal

Raj Kumar Beniwal is two time Microsoft MVP(Client App Dev) and four time C# Corner MVP,  working as project manager with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Serv... Read more