创建第一个Windows Phone应用程序(一)

 

文章出处 :http://create.msdn.com/en-US/education/quickstarts/Get_Started_Creating_a_Windows_Phone_Application

一、安装开发工具

下载和安装必须的开发工具,创建和发布Windows Phone应用程序。

C#开发人员

VB开发人员

如果是C#开发人员,需要安装下列工具和更新:

1.       Windows Phone Developer Tools

2.       Windows Phone Developer Tools January 2011 Update

如果是VB开发人员,需要安装 Visual Studio 2010 Professional, Premium, Ultimate版本才能使用Visual Basic for Windows Phone.,因为Visual Studio 2010 Express for Windows Phone不支持Visual Basic for Windows Phone.

1.       Windows Phone Developer Tools

2.       Windows Phone Developer Tools January 2011 Update

3.       Microsoft Visual Basic for Windows Phone Developer Tools - RTW

二、创建新windows phone 项目

1、 开始菜单,打开Visual Studio 2010 Express for Windows Phone

2、 文件菜单,点击New Project

Creating a new project

New Project对话框中,左边显示的是不同的项目模板,当选择Silverlight for Windows Phone,中间部分是可以选择创建的不同的应用程序类型

New Project dialog box

3、 左边选择Silverlight for Windows Phone

4、 中间选择Windows Phone Application template

5、 工程Name,输入HelloWord_PhoneLocation是您创建应用程序所在路径,点击OK按钮

Silverlight for Windows Phone 工程被自动创建,并在Visual Stuido Express中打开。

New Silverlight for Windows Phone project

默认情况下,Visual Sudio显示3个窗格(根据设置的不同,会有不同),左边为应用程序的界面设计预览,中间部分是XAML,右边是解决方案资源管理器(Solution Explorer.

Solution Explorer,显示了默认创建的文件,本文档中我们主要使用 MainPage.xaml and MainPage.xaml.cs.文件,MainPage.xaml定义了应用程序的用户界面,XAML一种基于XML的声明性语言,用于创建用户界面元素和布局展开MainPage.xaml,会看到C代码隐藏文件MainPage.xaml.csMainPage.xaml.cs包含了XAML的逻辑。从代码分离出用户界面,使用XAML标记语言创建可视用户在界面元素,然后使用一个单独的代码隐藏文件,以响应事件和操作XAML声明的对象。这种代码和界面的分离很容易让设计师和开发人员在同一个项目中高效率工作。

三、添加TextBock

接下来,我们将添加一个简单的TextBlock,显示消息“HelloWord!“。有不同的方式添加界面元素,本节中我们将使用ToolBoxDesign View

1、 Solution Explorer双击MainPage.xaml

2、 View菜单,点击Other Windows,单击ToolBox,出现ToolBox界面

Toolbox

3、 从工具箱拖动TextBlock控件到手机模拟器的主面板

4、 XAML视图中,可以看到一个TextBlock元素被添加到Grid中。

XAML

<!--ContentPanel - place additional content here-->

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,6,0,0"

Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" />

</Grid>

4.       View菜单,点击Other Windows,单击Properties Window.,属性窗口被打开

 Properties window

5.       Design view,选中TextBlock

6.       Properties window,设置Text 属性Hello, World!.

7.       设置FontSize 属性为50

8.       设置Height 属性为70

 Properties set on TextBlock

四、运行应用程序

现在已经创建了一个基于SilverlightWindows手机应用程序,我们将使用内置的WindowsPhone模拟器,它模仿Windows手机设备。使用Windows Phone模拟器,可以在桌面上测试和调试应用程序,而不必立即部署到设备上。
要启动模拟器,你只需要为应用程序启动调试, Visual Studio启动模拟器,并加载到它的应用程序

Debug模式下运行应用程序,按F5或者点击Debug菜单,点击Start Debuging

如果出现编译错误,Visual Studio将显示错误信息。如果没有错误,将打开Windows Phone模拟器,如下图所示:

Windows Phone emulator showing Hello World!

首次需要一些时来打开模拟器并启动调试器。为了加快调试,不要关闭模拟器窗口。选择Debug->Stop Debugging以停止调试。将离开模拟器中运行,这样下次调试时模拟器载入的更加快速

点击Debug->Stop Debuging,停止调试。

下一部分,为应用程序增加图形、按钮、简单动画。

创建第一个Windows Phone应用程序(二)

原文地址:https://www.cnblogs.com/kinglau/p/2073887.html