wp7開發之建立第一個Silverlight應用程式

來源:互聯網
上載者:User

           首先建立一個新的項目:

               開啟開發工具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還要簡單,哈哈!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.