zoukankan      html  css  js  c++  java
  • Windows Phone开发(25):启动器与选择器之WebBrowserTask 转:http://blog.csdn.net/tcjiaan/article/details/7404770

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

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

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

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

    1. <phone:PhoneApplicationPage   
    2.     x:Class="WebTask.MainPage"  
    3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"  
    6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"  
    7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
    8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"  
    10.     FontFamily="{StaticResource PhoneFontFamilyNormal}"  
    11.     FontSize="{StaticResource PhoneFontSizeNormal}"  
    12.     Foreground="{StaticResource PhoneForegroundBrush}"  
    13.     SupportedOrientations="Portrait" Orientation="Portrait"  
    14.     shell:SystemTray.IsVisible="True">  
    15.   
    16.     <!--LayoutRoot 是包含所有页面内容的根网格-->  
    17.     <Grid x:Name="LayoutRoot" Background="Transparent">  
    18.         <Grid.RowDefinitions>  
    19.             <RowDefinition Height="Auto"/>  
    20.             <RowDefinition Height="*"/>  
    21.         </Grid.RowDefinitions>  
    22.   
    23.         <!--TitlePanel 包含应用程序的名称和页标题-->  
    24.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">  
    25.             <TextBlock x:Name="ApplicationTitle" Text="我的应用程序" Style="{StaticResource PhoneTextNormalStyle}"/>  
    26.             <TextBlock x:Name="PageTitle" Text="启动Web浏览器" Margin="9,-7,0,0" FontSize="50"/>  
    27.         </StackPanel>  
    28.   
    29.         <!--ContentPanel - 在此处放置其他内容-->  
    30.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
    31.             <TextBlock Height="40" HorizontalAlignment="Left" Margin="38,57,0,0" Name="textBlock1" Text="请输入URL:" VerticalAlignment="Top" Width="286" FontSize="28"/>  
    32.             <TextBox Height="72" HorizontalAlignment="Left" Margin="12,122,0,0" Name="txtUrl" VerticalAlignment="Top" Width="394" />  
    33.             <Button Content="通过Uri对象设置并启动" Height="79" HorizontalAlignment="Left" Margin="12,222,0,0" Name="button1" VerticalAlignment="Top" Width="394" Click="button1_Click" />  
    34.             <Button Content="通过字符串设置并启动" Height="79" HorizontalAlignment="Left" Margin="9,323,0,0" Name="button2" VerticalAlignment="Top" Width="394" Click="button2_Click" />  
    35.         </Grid>  
    36.     </Grid>  
    37.    
    38.   
    39. </phone:PhoneApplicationPage>  
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Net;  
    5. using System.Windows;  
    6. using System.Windows.Controls;  
    7. using System.Windows.Documents;  
    8. using System.Windows.Input;  
    9. using System.Windows.Media;  
    10. using System.Windows.Media.Animation;  
    11. using System.Windows.Shapes;  
    12. using Microsoft.Phone.Controls;  
    13. using Microsoft.Phone.Tasks;  
    14.   
    15. namespace WebTask  
    16. {  
    17.     public partial class MainPage : PhoneApplicationPage  
    18.     {  
    19.         // 构造函数  
    20.         public MainPage()  
    21.         {  
    22.             InitializeComponent();  
    23.         }  
    24.   
    25.         private void button1_Click(object sender, RoutedEventArgs e)  
    26.         {  
    27.             // 通过Uri对象设置  
    28.             WebBrowserTask wt = new WebBrowserTask();  
    29.             wt.Uri = new Uri(txtUrl.Text, UriKind.Absolute);  
    30.             wt.Show();  
    31.         }  
    32.   
    33.         private void button2_Click(object sender, RoutedEventArgs e)  
    34.         {  
    35.             // 通过字符串设置  
    36.             WebBrowserTask wt = new WebBrowserTask();  
    37.             wt.URL = txtUrl.Text;  
    38.             wt.Show();  
    39.         }  
    40.     }  
    41. }  


  • 相关阅读:
    Appium+python自动化17-启动iOS模拟器APP源码案例
    Pycharm上python和unittest两种姿势傻傻分不清楚
    jenkins显示html样式问题的几种解决方案总结
    Appium+python自动化16-appium1.6在mac上环境搭建启动ios模拟器上Safari浏览器
    selenium+python在mac环境上的搭建
    python+requests接口自动化完整项目设计源码
    Appium+python自动化15-在Mac上环境搭建
    git使用教程2-更新github上代码
    git使用教程1-本地代码上传到github
    针对初学者的A*算法入门详解(附带Java源码)
  • 原文地址:https://www.cnblogs.com/songtzu/p/2607135.html
Copyright © 2011-2022 走看看