`

Windows Phone新手开发教程(四)

阅读更多

在这一部分里,我将讲解如何编写一个应用程序以及访问Windows Phone中文本框的值。

首先从编写应用程序说起。

编写第一个应用程序

从File菜单选择New project,并选择Windows Phone applicaton。将三个文本框添加到网格面板,前两个文本框用于输入数值,第三个文本框显示结果。

MainPage.xaml 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!--LayoutRoot is the root grid where all page content is placed--> 
<grid x:name="LayoutRoot" background="Transparent"
    <grid.rowdefinitions> 
        <rowdefinition height="Auto"
        <rowdefinition height="*"
    </rowdefinition></rowdefinition></grid.rowdefinitions> 
    <!--TitlePanel contains the name of the application and page title--> 
    <stackpanel x:name="TitlePanel" grid.row="0" margin="12,17,0,28"
        <textblock x:name="ApplicationTitle" text="MY APPLICATION" style="{StaticResource PhoneTextNormalStyle}"
        <textblock x:name="PageTitle" text="1st Application" margin="9,-7,0,0" style="{StaticResource PhoneTextTitle1Style}"
    </textblock></textblock></stackpanel> 
    <!--ContentPanel - place additional content here--> 
    <grid x:name="ContentPanel" grid.row="1" margin="12,0,12,0"
        <textblock x:name="lblfirst" text="Enter 1st Number" margin="25,38,241,527"></textblock> 
        <textblock x:name="lblsecond" text="Enter 2nd Number" margin="25,98,241,467"></textblock> 
        <textblock x:name="lblresult" text="Result" margin="25,161,241,404"></textblock> 
        <textbox x:name="txtfirst" margin="225,24,6,508"></textbox> 
        <textbox x:name="txtsecond" margin="225,84,6,450"></textbox> 
        <textbox x:name="txtresult" margin="225,147,6,381"></textbox> 
        <button x:name="btnadd" height="95" content="Addition" margin="0,232,0,280" click="btnadd_Click"></button> 
    </grid> 
</grid>
Windows Phone新手开发教程

现在为按钮的点击事件编写代码,第一个和第二个文本框接收用户输入的数据,第三个文本框显示两个数字相加的结果。

MainPage.xaml.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 WriteFirstApplication 
    public partial class MainPage : PhoneApplicationPage 
    
        // Constructor 
        public MainPage() 
        
            InitializeComponent(); 
        
   
        private void btnadd_Click(object sender, RoutedEventArgs e) 
        
              
            int result = Convert.ToInt32(txtfirst.Text)+Convert.ToInt32(txtsecond.Text); 
            txtresult.Text = result.ToString(); 
   
               
        
    
}

所有完成之后运行应用程序。

Windows Phone新手开发教程

现在编写显示运行消息的信息提示框。你只需要添加一行代码就可以完成信息提示框的设计。

MessageBox.Show(“YourContent”)

MainPage.xaml.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 WriteFirstApplication 
    public partial class MainPage : PhoneApplicationPage 
    
        // Constructor 
        public MainPage() 
        
            InitializeComponent(); 
        
   
        private void btnadd_Click(object sender, RoutedEventArgs e) 
        
              
            int result = Convert.ToInt32(txtfirst.Text)+Convert.ToInt32(txtsecond.Text); 
MessageBox.Show("Addition of "+ txtfirst.Text +"&"+ txtsecond.Text +"=" +result.ToString()); 
   
   
              
        
    
}
Windows Phone新手开发教程

本文翻译自c-sharpcorner.com,原文地址

0
2
分享到:
评论

相关推荐

    ArcGIS for Windows Phone开发教程

    基于ArcGIS for Windows Phone 最新版API v3.0撰写的开发教程,适合windows Phone开发新手和感兴趣的同学。

    微软的 windows phone 开发教程 (word)

    【微软Windows Phone开发教程】 Windows Phone是由微软公司开发的一款移动操作系统,主要面向智能手机市场,与Android和iOS形成竞争。在Windows Phone系统上进行应用开发,开发者可以利用微软提供的强大工具和平台...

    ArcGIS API for Windows Phone开发教程

    ArcGIS API for Windows Phone开发教程,很不错的教程,以超市信息管理为例,详细讲解每一步的实现过程,即使是windows phone开发新手也能按照教程学习开发。推荐给新手。

    Windows_Phone_7开发教程汇总

    总的来说,Windows Phone 7开发教程汇总提供了一条清晰的学习路径,适合新手入门,也对经验丰富的开发者有参考价值。通过这一系列教程,开发者不仅可以掌握开发Windows Phone 7应用的基础技能,还能了解到如何利用这...

    XapNote - 四天玩转 Windows Phone 开发 | 第四天

    该教程基于微软官方的Windows Phone开发教学系列视频,旨在帮助开发者在短短四天内掌握Windows Phone应用开发的基础知识。 第四天的内容通常会涵盖以下几个核心知识点: 1. **Silverlight for Windows Phone**: ...

    Windows Phone 7完整硬件控件教程

    总的来说,《Windows Phone 7完整硬件控件教程》是一份详尽的学习资料,对于希望在Windows Phone 7平台上开发高效、创新应用的开发者来说,无论是新手还是有经验的开发者,都能从中受益匪浅。通过学习和实践,开发者...

    Windows Phone实用开发技巧 1-20集合

    在Windows Phone平台上进行应用开发是一项技术性强且富有挑战性的工作,尤其对于新手开发者而言。"Windows Phone实用开发技巧 1-20集合"提供了一系列的教程和指导,旨在帮助开发者们掌握这一领域的核心技能和最佳...

    windowsphone SDK 精简版

    10. **兼容性**:虽然Windows Phone SDK 7.1主要是为了开发7.1版应用,但它通常也可以用来创建和修改早期版本Windows Phone应用,但可能不支持后来的Windows Phone 8或更高版本的特定特性。 总之,Windows Phone ...

    Windows_Mobile开发新手入门教程

    用于windows 移动开发的入门,环境搭建和简单编程

    Windows Phone Software Development Kit (SDK) 7.1

    除了官方SDK,Windows Phone开发者社区也提供了大量的教程、示例代码和论坛讨论,帮助新手快速上手并解决开发过程中遇到的问题。 总的来说,Windows Phone SDK 7.1是开发人员构建创新Windows Phone应用程序的关键...

    Windows Mobile开发新手入门教程

    Windows Mobile开发新手入门教程是一份专为初学者设计的学习资源,旨在帮助那些对移动应用开发感兴趣的人快速掌握在Windows Mobile平台上构建应用程序的基本技能。Windows Mobile是微软推出的一种面向移动设备的操作...

    Windows Phone7帮助文档

    Windows Phone Developer Tools Documentation.chm文件包含了大量的技术文档、教程和参考信息,开发者可以通过搜索功能快速查找所需内容。 2. CHW( Compiled Help Workshop):是用于创建CHM文件的工具。虽然在...

    beginning windows phone 7 development

    《初识Windows Phone 7开发》是一本专为英语熟练者设计的教程,旨在引导读者进入Windows Phone 7应用程序的开发世界。这本书深入浅出地介绍了这个平台的基础知识,为那些想要利用C#和XAML语言开发WP7应用的开发者...

    windows phone 7 简单程序

    在本教程中,我们将专注于构建你的第一个 Windows Phone 7 应用程序,这是一个简单而直观的过程。首先,你需要安装必要的开发工具,包括 Microsoft Visual Studio 2010 Express 版本,这是专为 Windows Phone 开发...

    Windows phone 教学视频09

    【标题】"Windows phone 教学视频09" 涉及的是Windows Phone 8平台的应用开发教程,尤其是关于在不同应用之间进行通信的技术。在Windows Phone生态系统中,应用程序通常被设计为相互独立的,但有时为了提供更好的...

    Programming_Windows_Phone_7

    《编程Windows Phone 7》是Charles Petzold撰写的一本专为初学者设计的Windows Phone 7开发指南。这本书深入浅出地介绍了如何利用Microsoft的工具和技术构建Windows Phone 7应用程序。Petzold是一位备受尊敬的技术...

    Windows Phone 用户和自定义控件例子程序

    本教程将通过“Windows Phone 用户和自定义控件例子程序”这一主题,深入探讨如何利用XAML进行界面设计以及如何自定义控件以满足特定需求。 XAML是一种基于XML的语言,主要用于描述UI元素和它们的属性,使得开发者...

    windows mobile 开发者新手上路指南.rar

    Windows Mobile开发者新手上路指南是针对想要在移动设备上利用微软Windows Mobile操作系统进行应用程序开发的初学者准备的一份详尽教程。这份指南旨在帮助你快速理解并掌握Windows Mobile开发的基本概念、工具和流程...

    Unity iPhone Newbie Tutorial Series

    Unity iPhone新手教程系列是针对想要入门Unity引擎在iOS平台开发游戏或应用的初学者们的一套详尽指南。本教程涵盖了从安装Unity到创建第一个iPhone应用程序的全过程,旨在帮助新手快速掌握Unity的基础知识和iPhone...

    Python完全新手教程

    Windows用户则可以在安装Python后,通过开始菜单找到IDLE,这是一个集成开发环境(IDE),也具有交互式提示符。 **Lesson 1:设置Python环境和基础操作** 在Python的交互式环境中,你可以直接输入代码并立即查看...

Global site tag (gtag.js) - Google Analytics