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

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

从名字上就看出来,这个家伙就是打开浏览并浏览到指定页面。

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

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

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

<phone:PhoneApplicationPage
    x:Class="WebTask.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel 包含应用程序的名称和页标题-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="启动Web浏览器" Margin="9,-7,0,0" FontSize="50"/>
        </StackPanel>

        <!--ContentPanel - 在此处放置其他内容-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock Height="40" HorizontalAlignment="Left" Margin="38,57,0,0" Name="textBlock1" Text="请输入URL:" VerticalAlignment="Top" Width="286" FontSize="28"/>
            <TextBox Height="72" HorizontalAlignment="Left" Margin="12,122,0,0" Name="txtUrl" VerticalAlignment="Top" Width="394" />
            <Button Content="通过Uri对象设置并启动" Height="79" HorizontalAlignment="Left" Margin="12,222,0,0" Name="button1" VerticalAlignment="Top" Width="394" Click="button1_Click" />
            <Button Content="通过字符串设置并启动" Height="79" HorizontalAlignment="Left" Margin="9,323,0,0" Name="button2" VerticalAlignment="Top" Width="394" Click="button2_Click" />
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>
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();
        }
    }
}

时间: 2024-07-29 19:32:02

Windows Phone开发(25):启动器与选择器之WebBrowserTask的相关文章

Windows Phone开发(22):启动器与选择器之BingMapsDirectionsTask

原文:Windows Phone开发(22):启动器与选择器之BingMapsDirectionsTask 从今天开发始,我们又开始新的征程,接下来的课程我们要熟悉一下启动器和选择器,其实二者是一样的,没有根本的区别,启动器是有返回结果的,如打开搜索应用程序进行搜索,而选择器是有返回内容的,如选择一张照片.   那么,启动器和选择器是啥玩意儿呢?其实我们可以很简单去理解,说白了,就是使用系自带的组件或应用程序.对的,就是这样,我说过,有时候很多概念只是名字上吓人罢了,实际用起来是非常简单的,比如

Windows Phone开发(23):启动器与选择器之CameraCaptureTask和PhotoChooserTask

原文:Windows Phone开发(23):启动器与选择器之CameraCaptureTask和PhotoChooserTask 这两个组件都属于选择器,而且它们也有很多相似的地方,最明显的上一点,它们都是用来选择图片.     一.CameraCaptureTask选择器.   它用于启动照相机,当你拍下照片后,自动把照的字节流返回给调用方应用程序.前文说过,启动器和选择的使用方法和步骤都是一样的.对于CameraCaptureTask组件也如此,不过注意的一点是,处理Completed事件

Windows Phone开发(24):启动器与选择器之发送短信

原文:Windows Phone开发(24):启动器与选择器之发送短信 本节我们通过一个简单的发送短信示例来演示一下如果配合使用PhoneNumberChooserTask和SmsComposeTask类. PhoneNumberChooserTask是选择器,它用于从你的电话簿里选择你要发送短信的电话号码: SmsComposeTask就是用来启动发送短信组件并显示发送窗口. 注意,这些操作都在用户的操控之中,发送短信一定会显示可视化页面的,而且不会偷偷地在后台发送,因为Windows pho

Windows Phone开发(26):启动器与选择器之MediaPlayerLauncher和SearchTask

原文:Windows Phone开发(26):启动器与选择器之MediaPlayerLauncher和SearchTask 启动器与选择器简单的地方在于,它们的使用方法几乎一模一样,从前面几节中,我相信大家基本上都知道如何使用它们了. 这里还是哆嗦一下吧,使用启动器和选择器的步骤如下: 1.实例化,new一个: 2.准备各参数,对相关的属性赋值: 3.Show: 4.对于启动器,不需要这步,但选择器有返回数据,所以需要处理完成事件. 本节再举两例子,启动器和选择器就可以完成了,然后我们下一节开始

Windows 8开发入门(十八)windows 8开发模拟器和程序中关联文件类型

本文将讲解两个内容,1.Windows 8 开发模拟器的使用.2.程序中设置关联文件类型. 一. Windows 8 开发模拟器的使用 1.在VS2012中自带有Windows 8开发模拟器,我们选择VS界面中的调试按 钮从"本地计算器"改选为"Simulater"模拟器即可,如下图: 2.点击"Simulator"按钮即可弹出以下界面 3.此时我们可以看到模拟器上面有很多按钮这些按钮的功能有模拟单点触摸.多点触摸.旋转设备等操作 .我们在这里可

Windows App开发之开发准备

操作系统及SDK 操作系统 显而易见,想要开发Windows App就得在Windows 8/8.1/10上进行,老旧的Windows XP/Vista/7已经不能满足时代的需要了.当然,在Windows App的发展过程中,其本身也有着较大的变动,为了使用新的特性,建议使用Windows 10.我在写这个教程时,Windows 10正式版并未面世,因此暂时未介绍Windows 10上的新特性,随后会继续更新,欢迎您的继续关注. 操作系统除了在官网下载之外,还可以在DreamSpark等地方下载

Windows App开发之文件与数据

读取文件和文件夹名 这一节开始我们将陆续看到Windows App是怎样操作文件的. 在Windows上读取文件名.文件夹名 首先我们在XAML中定义一个Button和TextBlock,将读取文件/文件夹名的过程写在前者的click事件中,后者则用来显示文件信息. <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Orientation="

Windows 10开发基础——文件、文件夹和库(一)

原文:Windows 10开发基础--文件.文件夹和库(一) 主要内容:      1.枚举查询文件和文件夹      2.文本文件读写的三种方法--创建写入和读取文件      3.获得文件的属性   枚举查询文件和文件夹 先了解一下文件查询的几个方法: StorageFolder.GetFilesAsync: 获取当前文件夹中的所有文件,返回一个 IReadOnlyList<StorageFile>集合          IReadOnlyList<StorageFile> f

【万里征程——Windows App开发】开发准备

操作系统及SDK 操作系统 如果打算开发Windows App,那么你的电脑就不能再用老旧的Windows 7了.推荐使用Windows 8.1.写这篇博客的时候,我用的操作系统是Windows 10 Pro Technical Preview [Build 10041]. 操作系统除了在官网下载之外,还可以在DreamSpark等地方下载.DreamSpark上除了Office其他微软操作系统.开发工具及其他软件对学生均免费开放. 另外再推荐一个网站:MSDN i tell you Visua