wp7开发之创建第一个Silverlight应用程序

           首先创建一个新的项目:

               打开开发工具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还要简单,哈哈!


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值