首先建立一個新的項目:
開啟開發工具File/new Project:
,修改自己為項目定義的名字。
點擊OK 就進入到了如下介面:
雙擊 page name 字型 在右下角Properties中修改Text 的內容為my browser。
然後在最左邊Toolbox,拖拽一個button 和TextBox 到視圖介面 ,然後分別修改button的內容為go 和TextBox 的內容為http://blog.csdn.net/wangkuifeng0118,最後在拖拽一個WebBrowser控制項到視圖中:
會出現如所示的介面效果,其中右邊的MainPage.xaml中新增加了如下代碼:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Button Content="go" Height="72" HorizontalAlignment="Left" Margin="345,45,0,0" Name="button1" VerticalAlignment="Top" Width="111" Click="button1_Click" /> <TextBox Height="72" HorizontalAlignment="Left" Margin="0,45,0,0" Name="textBox1" Text="http//www.xbox.com" VerticalAlignment="Top" Width="356" TextChanged="textBox1_TextChanged" /> <phone:WebBrowser HorizontalAlignment="Stretch" Margin="0,84,0,0" Name="webBrowser1" VerticalAlignment="Stretch" Height="Auto" Width="Auto" /> </Grid>
接下來添加button 相應事件,雙擊go按鈕 會進入到MainPage.xaml.cs:
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;namespace myFirstPhone{ public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { } }}
編寫如下代碼:
private void button1_Click(object sender, RoutedEventArgs e) { //得到TextBox控制項中的值 String site = textBox1.Text; //啟動webBrowser webBrowser1.Navigate(new Uri(site,UriKind.Absolute)); }
代碼已經編寫完成,下面看一下運行和調試:
點擊綠色按鈕,開始調試。
出現介面,然後點擊go按鈕 :
完成,總體開發起來,好像比android還要簡單,哈哈!