开发者

How to launch IE7 from a Windows Phone App?

开发者_如何学JAVAHow do you launch an instance of IE from an app? Is it better practice to page to a window with and browser window?


You can launch a URI in the browser using the WebBrowserTask.

Use it like this:

var wbt = new WebBrowserTask();
wbt.URL = "http://stackoverflow.com/";
wbt.Show();


In Windows Phone 8, URL has been phased out. Use this instead:

WebBrowserTask webBrowserTask = new WebBrowserTask();

webBrowserTask.Uri = new Uri("http://msdn.microsoft.com", UriKind.Absolute);

webBrowserTask.Show();

See the documentation on the IE task at MSDN.


You need to use the WebBrowserTask:

WebBrowserTask browser = new WebBrowserTask();
browser.URL = "http://www.google.com";
browser.Show();


Matt and Oliver have already answered the question, but I was looking for this and thought some extra information would be helpful since I hate tracking down namespaces:

  • You have to have a reference to the Microsoft.Phone.dll (Automatic in Silverlight Apps)
  • You need to put using Microsoft.Phone.Tasks; at the top of your class (this is the namespace where the WebBrowserTask is declared).

Then you can use the code shown above, or use this slight variation:

WebBrowserTask task = new WebBrowserTask() { URL = "http://wirebear.com/blog" };
task.Show();

As long as you have handled tombstoning in your app, the user can just hit back to return which is usually the desired behavior. Another bonus is that the loading of the browser integrates really well in WP7 so that it actually looks like it's part of your app. The browser comes in with a turnstile animation and keeps your appBar showing for a moment then flips them to the browser icons - a very nice effect for just 2 lines of code!


Just so you are aware, you can also embed a browser within your app using WebBrowser control.

It's there in the toolbox, just drag it on your page. You can navigate with code if you want like..

private void webBrowser1_Loaded(object sender, RoutedEventArgs e) {
    webBrowser1.Navigate(new Uri("http://www.bing.com/", UriKind.Absolute));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜