Windows Phone開發(25):啟動器與選取器之WebBrowserTask

來源:互聯網
上載者:User

從名字上就看出來,這個傢伙就是開啟瀏覽並瀏覽到指定頁面。

 

它有兩個用途完全一樣的屬性:Uri屬性是System.Uri類型,這是新寫進的屬性;

URL是字串類型,但如果使用該屬性,會發出警告“已淘汰”,所以建議使用前者。

 

下面這個例子,點擊按鈕後都是開啟WEB瀏覽器並定位到文字框中輸入的地址,但分別用了上面所說的兩個屬性,當程式運行後,你會發現其效果是一樣的。

 

<phone:PhoneApplicationPage<br /> x:Class="WebTask.MainPage"<br /> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br /> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br /> xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"<br /> xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"<br /> xmlns:d="http://schemas.microsoft.com/expression/blend/2008"<br /> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"<br /> mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"<br /> FontFamily="{StaticResource PhoneFontFamilyNormal}"<br /> FontSize="{StaticResource PhoneFontSizeNormal}"<br /> Foreground="{StaticResource PhoneForegroundBrush}"<br /> SupportedOrientations="Portrait" Orientation="Portrait"<br /> shell:SystemTray.IsVisible="True"></p><p> <!--LayoutRoot 是包含所有頁面內容的根網格--><br /> <Grid x:Name="LayoutRoot" Background="Transparent"><br /> <Grid.RowDefinitions><br /> <RowDefinition Height="Auto"/><br /> <RowDefinition Height="*"/><br /> </Grid.RowDefinitions></p><p> <!--TitlePanel 包含應用程式的名稱和網頁標題--><br /> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"><br /> <TextBlock x:Name="ApplicationTitle" Text="我的應用程式" Style="{StaticResource PhoneTextNormalStyle}"/><br /> <TextBlock x:Name="PageTitle" Text="啟動Web瀏覽器" Margin="9,-7,0,0" FontSize="50"/><br /> </StackPanel></p><p> <!--ContentPanel - 在此處放置其他內容--><br /> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"><br /> <TextBlock Height="40" HorizontalAlignment="Left" Margin="38,57,0,0" Name="textBlock1" Text="請輸入URL:" VerticalAlignment="Top" Width="286" FontSize="28"/><br /> <TextBox Height="72" HorizontalAlignment="Left" Margin="12,122,0,0" Name="txtUrl" VerticalAlignment="Top" Width="394" /><br /> <Button Content="通過Uri對象設定並啟動" Height="79" HorizontalAlignment="Left" Margin="12,222,0,0" Name="button1" VerticalAlignment="Top" Width="394" Click="button1_Click" /><br /> <Button Content="通過字串設定並啟動" Height="79" HorizontalAlignment="Left" Margin="9,323,0,0" Name="button2" VerticalAlignment="Top" Width="394" Click="button2_Click" /><br /> </Grid><br /> </Grid></p><p></phone:PhoneApplicationPage>

using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Net;<br />using System.Windows;<br />using System.Windows.Controls;<br />using System.Windows.Documents;<br />using System.Windows.Input;<br />using System.Windows.Media;<br />using System.Windows.Media.Animation;<br />using System.Windows.Shapes;<br />using Microsoft.Phone.Controls;<br />using Microsoft.Phone.Tasks;</p><p>namespace WebTask<br />{<br /> public partial class MainPage : PhoneApplicationPage<br /> {<br /> // 建構函式<br /> public MainPage()<br /> {<br /> InitializeComponent();<br /> }</p><p> private void button1_Click(object sender, RoutedEventArgs e)<br /> {<br /> // 通過Uri對象設定<br /> WebBrowserTask wt = new WebBrowserTask();<br /> wt.Uri = new Uri(txtUrl.Text, UriKind.Absolute);<br /> wt.Show();<br /> }</p><p> private void button2_Click(object sender, RoutedEventArgs e)<br /> {<br /> // 通過字串設定<br /> WebBrowserTask wt = new WebBrowserTask();<br /> wt.URL = txtUrl.Text;<br /> wt.Show();<br /> }<br /> }<br />}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.