Wednesday, May 18, 2011

Web Browser Control Windows Phone7 (WP7)

Recently I was just playing with the Web Browser in Windows Phone 7 (WP7) & got error as " You cannot call WebBrowser methods until it is in the visual tree " . So thought to share some basic ideas.

Once you drag and drop the WebBrowser control from tool box , you can see code below in .xaml file.<phone:WebBrowser Name="WebBrowser1" Height="676" Width="450" />Initially Screen looks like ( refer Screen1)

Now there are two ways to navigate to your web contents :1. You need to update the Source property of the Web Browser control in .xaml file: e.g. <phone:WebBrowser Source="http://www.mohzz.com" Name="WebBrowser1" Height="676" Width="450" />

If we update like above then your web contents will show default contents from specified source ( i.e. contents from "http://www.mohzz.com")( refer Screen2)

2. Second way is , No need to update the Source property of the Web Browser control in .xaml file:it will remains as it is <phone:WebBrowser Name="WebBrowser1" Height="227" Width="460" />

Now you need Set URI location of the Web browser control your codebase accordingly.You can set URI location by using either "WebBrowser1.Source" property or by calling "WebBrowser1.Navigate('uri parameter') "

No comments:

Post a Comment

Search

About Me

Mohsin Shaikh is a computer science graduate, holding master degree in computer applications. Presently working as a Senior Software Engineer in a private organisation located in Silicon Valley(Bangalore) , India.