您的位置:首页 > 其它

Windows Phone开发(25):启动器与选择器之WebBrowserTask

2012-03-28 21:31 375 查看
从名字上就看出来,这个家伙就是打开浏览并浏览到指定页面。

它有两个用途完全一样的属性:Uri属性是System.Uri类型,这是新写进的属性;

URL是字符串类型,但如果使用该属性,会发出警告“已过时”,所以建议使用前者。

下面这个例子,点击按钮后都是打开WEB浏览器并定位到文本框中输入的地址,但分别用了上面所说的两个属性,当程序运行后,你会发现其效果是一样的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace WebTask
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
// 通过Uri对象设置
WebBrowserTask wt = new WebBrowserTask();
wt.Uri = new Uri(txtUrl.Text, UriKind.Absolute);
wt.Show();
}

private void button2_Click(object sender, RoutedEventArgs e)
{
// 通过字符串设置
WebBrowserTask wt = new WebBrowserTask();
wt.URL = txtUrl.Text;
wt.Show();
}
}
}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐