<!--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 Text="www.baidu.com" 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" />
<TextBlock TextWrapping="Wrap" Height="143" HorizontalAlignment="Left" Margin="19,464,0,0" Name="textBlock2" Text="设置浏览器的主页,这两种方法都可以 第一种格式为:hhtp://www.bai.com 第二种方法为:www.baidu.com" VerticalAlignment="Top" Width="437" FontSize="25" />
</Grid>
</Grid>
后台代码:
private void button1_Click(object sender, RoutedEventArgs e)
{
// 通过Uri对象设置
try
{
WebBrowserTask wt = new WebBrowserTask();
wt.Uri = new Uri(txtUrl.Text, UriKind.Absolute);
wt.Show();
}
catch { MessageBox.Show("格式不正确,请注意格式!!!"); }
}
private void button2_Click(object sender, RoutedEventArgs e)
{
// 通过字符串设置
WebBrowserTask wt = new WebBrowserTask();
wt.URL = txtUrl.Text;
wt.Show();
}