Hello Phone 项目包含以下项 (Item):

Item
Description

App.xaml / App.xaml.cs
定义应用程序的入口点,初始化应用程序范围内的资源,,显示应用程序用户界面

MainPage.xaml / MainPage.xaml.cs
定义应用程序中的程序页面(带有用户界面的页面)

ApplicationIcon.png
一种带有图标的图像文件,代表了手机应用程序列表中应用程序的图标

Background.png
一种带有图标的图像文件,代表了在开始页面上应用程序的图表

SplashScreenImage.jpg
这个图片会在应用程序第一次被启动时显示。启动画面会给用户一个即时的反馈,告诉用户应用程序正在启动直到成功跳转到应用程序的第一个页面。用户的启动画面可以和应用程序的一个页面设计的非常相似,这样能给使用这一个应用程序被快速加载的感觉。

Properties\AppManifest.xml
一个生成应用程序包所必需的应用程序清单文件

Properties\AssemblyInfo.cs
包含名称和版本的元数据,这些元数据将被嵌入到生成的程序集

Properties\WMAppManifest.xml
一个包含与Windows Phone Silverlight应用程序相关的特定元数据的清单文件,且包含了用于Windows Phone的Silverlight所具有的特定功能

References folder
一些库文件(集)的列表,为应用程序的工作提供功能和服务。

 

 

App.xaml / App.xaml.cs

 

  1. 代码  
  2.  
  3. <Application   
  4.     x:Class="HelloPhone.App" 
  5.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         
  6.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  7.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  8.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"> 
  9.  
  10.     <!--Application Resources--> 
  11.     <Application.Resources> 
  12.     </Application.Resources> 
  13.  
  14.     <Application.ApplicationLifetimeObjects> 
  15.         <!--Required object that handles lifetime events for the application--> 
  16.         <shell:PhoneApplicationService   
  17.             Launching="Application_Launching" Closing="Application_Closing"   
  18.             Activated="Application_Activated" Deactivated="Application_Deactivated"/> 
  19.     </Application.ApplicationLifetimeObjects> 
  20.  
  21. </Application> 

 

  1. 代码  
  2.  
  3. // ----------------------------------------------------------------------------------  
  4. // Microsoft Developer & Platform Evangelism  
  5. //   
  6. // Copyright (c) Microsoft Corporation. All rights reserved.  
  7. //   
  8. // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,   
  9. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES   
  10. // OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.  
  11. // ----------------------------------------------------------------------------------  
  12. // The example companies, organizations, products, domain names,  
  13. // e-mail addresses, logos, people, places, and events depicted  
  14. // herein are fictitious.  No association with any real company,  
  15. // organization, product, domain name, email address, logo, person,  
  16. // places, or events is intended or should be inferred.  
  17. // ----------------------------------------------------------------------------------  
  18.  
  19. using System;  
  20. using System.Collections.Generic;  
  21. using System.Linq;  
  22. using System.Net;  
  23. using System.Windows;  
  24. using System.Windows.Controls;  
  25. using System.Windows.Documents;  
  26. using System.Windows.Input;  
  27. using System.Windows.Media;  
  28. using System.Windows.Media.Animation;  
  29. using System.Windows.Navigation;  
  30. using System.Windows.Shapes;  
  31. using Microsoft.Phone.Controls;  
  32. using Microsoft.Phone.Shell;  
  33.  
  34. namespace HelloPhone  
  35. {  
  36.     public partial class App : Application  
  37.     {  
  38.         /// <summary> 
  39.         /// Provides easy access to the root frame of the Phone Application.  
  40.         /// </summary> 
  41.         /// <returns>The root frame of the Phone Application.</returns> 
  42.         public PhoneApplicationFrame RootFrame { get; private set; }  
  43.  
  44.         /// <summary> 
  45.         /// Constructor for the Application object.  
  46.         /// </summary> 
  47.         public App()  
  48.         {  
  49.             // Global handler for uncaught exceptions.   
  50.             UnhandledException += Application_UnhandledException;  
  51.  
  52.             // Show graphics profiling information while debugging.  
  53.             if (System.Diagnostics.Debugger.IsAttached)  
  54.             {  
  55.                 // Display the current frame rate counters.  
  56.                 Application.Current.Host.Settings.EnableFrameRateCounter = true;  
  57.  
  58.                 // Show the areas of the app that are being redrawn in each frame.  
  59.                 //Application.Current.Host.Settings.EnableRedrawRegions = true;  
  60.  
  61.                 // Enable non-production analysis visualization mode,   
  62.                 // which shows areas of a page that are being GPU accelerated with a colored overlay.  
  63.                 //Application.Current.Host.Settings.EnableCacheVisualization = true;  
  64.             }  
  65.  
  66.             // Standard Silverlight initialization  
  67.             InitializeComponent();  
  68.  
  69.             // Phone-specific initialization  
  70.             InitializePhoneApplication();  
  71.         }  
  72.  
  73.         // Code to execute when the application is launching (eg, from Start)  
  74.         // This code will not execute when the application is reactivated  
  75.         private void Application_Launching(object sender, LaunchingEventArgs e)  
  76.         {  
  77.         }  
  78.  
  79.         // Code to execute when the application is activated (brought to foreground)  
  80.         // This code will not execute when the application is first launched  
  81.         private void Application_Activated(object sender, ActivatedEventArgs e)  
  82.         {  
  83.         }  
  84.  
  85.         // Code to execute when the application is deactivated (sent to background)  
  86.         // This code will not execute when the application is closing  
  87.         private void Application_Deactivated(object sender, DeactivatedEventArgs e)  
  88.         {  
  89.         }  
  90.  
  91.         // Code to execute when the application is closing (eg, user hit Back)  
  92.         // This code will not execute when the application is deactivated  
  93.         private void Application_Closing(object sender, ClosingEventArgs e)  
  94.         {  
  95.         }  
  96.  
  97.         // Code to execute if a navigation fails  
  98.         private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)  
  99.         {  
  100.             if (System.Diagnostics.Debugger.IsAttached)  
  101.             {  
  102.                 // A navigation has failed; break into the debugger  
  103.                 System.Diagnostics.Debugger.Break();  
  104.             }  
  105.         }  
  106.  
  107.         // Code to execute on Unhandled Exceptions  
  108.         private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)  
  109.         {  
  110.             if (System.Diagnostics.Debugger.IsAttached)  
  111.             {  
  112.                 // An unhandled exception has occurred; break into the debugger  
  113.                 System.Diagnostics.Debugger.Break();  
  114.             }  
  115.         }  
  116.  
  117.         #region Phone application initialization  
  118.  
  119.         // Avoid double-initialization  
  120.         private bool phoneApplicationInitialized = false;  
  121.  
  122.         // Do not add any additional code to this method  
  123.         private void InitializePhoneApplication()  
  124.         {  
  125.             if (phoneApplicationInitialized)  
  126.                 return;  
  127.  
  128.             // Create the frame but don't set it as RootVisual yet; this allows the splash  
  129.             // screen to remain active until the application is ready to render.  
  130.             RootFrame = new PhoneApplicationFrame();  
  131.             RootFrame.Navigated += CompleteInitializePhoneApplication;  
  132.  
  133.             // Handle navigation failures  
  134.             RootFrame.NavigationFailed += RootFrame_NavigationFailed;  
  135.  
  136.             // Ensure we don't initialize again  
  137.             phoneApplicationInitialized = true;  
  138.         }  
  139.  
  140.         // Do not add any additional code to this method  
  141.         private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)  
  142.         {  
  143.             // Set the root visual to allow the application to render  
  144.             if (RootVisual != RootFrame)  
  145.                 RootVisual = RootFrame;  
  146.  
  147.             // Remove this handler since it is no longer needed  
  148.             RootFrame.Navigated -CompleteInitializePhoneApplication;  
  149.         }  
  150.  
  151.         #endregion  
  152.     }  

页面布局

\HelloPhone\MainPage.xaml

 

  1. 代码  
  2.  
  3. <phone:PhoneApplicationPage   
  4.     x:Class="HelloPhone.MainPage" 
  5.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  6.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  7.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  8.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  9.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  10.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  11.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  12.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  13.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  14.     Foreground="{StaticResource PhoneForegroundBrush}" 
  15.     SupportedOrientations="Portrait" Orientation="Portrait" 
  16.     shell:SystemTray.IsVisible="True"> 
  17.  
  18.     <!--LayoutRoot is the root grid where all page content is placed--> 
  19.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  20.         <Grid.RowDefinitions> 
  21.             <RowDefinition Height="Auto"/> 
  22.             <RowDefinition Height="Auto"/> 
  23.             <RowDefinition Height="*"/> 
  24.         </Grid.RowDefinitions> 
  25.  
  26.         <!--TitlePanel contains the name of the application and page title--> 
  27.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  28.             <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/> 
  29.             <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
  30.         </StackPanel> 
  31.  
  32.         <!--ContentPanel - place additional content here--> 
  33.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
  34.             <Grid.ColumnDefinitions> 
  35.                 <ColumnDefinition Width="*" /> 
  36.                 <ColumnDefinition Width="Auto"/> 
  37.             </Grid.ColumnDefinitions> 
  38.             <TextBox Grid.Column="0" Name="MessageTextBox" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Margin="20,20,10,20"/> 
  39.             <Button Grid.Column="1" Name="ClickMeButton" Content="Click Me" HorizontalAlignment="Right" Padding="4" Margin="10,20,20,20" Click="ClickMeButton_Click" /> 
  40.         </Grid> 
  41.         <Grid Grid.Row="2"> 
  42.             <TextBlock Name="BannerTextBlock" Style="{StaticResource PhoneTextExtraLargeStyle}"   
  43.                Foreground="#FFFF9A00" HorizontalAlignment="Stretch" 
  44.                TextWrapping="Wrap" TextAlignment="Center" FontWeight="Bold" /> 
  45.         </Grid> 
  46.     </Grid> 
  47.    
  48.     <!--Sample code showing usage of ApplicationBar--> 
  49.     <!--<phone:PhoneApplicationPage.ApplicationBar> 
  50.         <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> 
  51.             <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/> 
  52.             <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/> 
  53.             <shell:ApplicationBar.MenuItems> 
  54.                 <shell:ApplicationBarMenuItem Text="MenuItem 1"/> 
  55.                 <shell:ApplicationBarMenuItem Text="MenuItem 2"/> 
  56.             </shell:ApplicationBar.MenuItems> 
  57.         </shell:ApplicationBar> 
  58.     </phone:PhoneApplicationPage.ApplicationBar>--> 
  59.  
  60. </phone:PhoneApplicationPage> 

后台代码

\HelloPhone\MainPage.xaml.cs

 

  1. 代码  
  2.  
  3. // ----------------------------------------------------------------------------------  
  4. // Microsoft Developer & Platform Evangelism  
  5. //   
  6. // Copyright (c) Microsoft Corporation. All rights reserved.  
  7. //   
  8. // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,   
  9. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES   
  10. // OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.  
  11. // ----------------------------------------------------------------------------------  
  12. // The example companies, organizations, products, domain names,  
  13. // e-mail addresses, logos, people, places, and events depicted  
  14. // herein are fictitious.  No association with any real company,  
  15. // organization, product, domain name, email address, logo, person,  
  16. // places, or events is intended or should be inferred.  
  17. // ----------------------------------------------------------------------------------  
  18.  
  19. using System;  
  20. using System.Collections.Generic;  
  21. using System.Linq;  
  22. using System.Net;  
  23. using System.Windows;  
  24. using System.Windows.Controls;  
  25. using System.Windows.Documents;  
  26. using System.Windows.Input;  
  27. using System.Windows.Media;  
  28. using System.Windows.Media.Animation;  
  29. using System.Windows.Shapes;  
  30. using Microsoft.Phone.Controls;  
  31.  
  32. namespace HelloPhone  
  33. {  
  34.     public partial class MainPage : PhoneApplicationPage  
  35.     {  
  36.         // Constructor  
  37.         public MainPage()  
  38.         {  
  39.             InitializeComponent();  
  40.         }  
  41.  
  42.         private void ClickMeButton_Click(object sender, RoutedEventArgs e)  
  43.         {  
  44.             BannerTextBlock.Text = MessageTextBox.Text;  
  45.             MessageTextBox.Text = String.Empty;  
  46.         }  
  47.     }  

Properties\AppManifest.xml

 

  1. <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">    <Deployment.Parts>    </Deployment.Parts></Deployment> 

Properties\AssemblyInfo.cs

 

  1. 代码  
  2.  
  3. // ----------------------------------------------------------------------------------  
  4. // Microsoft Developer & Platform Evangelism  
  5. //   
  6. // Copyright (c) Microsoft Corporation. All rights reserved.  
  7. //   
  8. // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,   
  9. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES   
  10. // OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.  
  11. // ----------------------------------------------------------------------------------  
  12. // The example companies, organizations, products, domain names,  
  13. // e-mail addresses, logos, people, places, and events depicted  
  14. // herein are fictitious.  No association with any real company,  
  15. // organization, product, domain name, email address, logo, person,  
  16. // places, or events is intended or should be inferred.  
  17. // ----------------------------------------------------------------------------------  
  18.  
  19. using System.Reflection;  
  20. using System.Runtime.CompilerServices;  
  21. using System.Runtime.InteropServices;  
  22.  
  23. // General Information about an assembly is controlled through the following   
  24. // set of attributes. Change these attribute values to modify the information  
  25. // associated with an assembly.  
  26. [assembly: AssemblyTitle("HelloPhone")]  
  27. [assembly: AssemblyDescription("")]  
  28. [assembly: AssemblyConfiguration("")]  
  29. [assembly: AssemblyCompany("Microsoft")]  
  30. [assembly: AssemblyProduct("HelloPhone")]  
  31. [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]  
  32. [assembly: AssemblyTrademark("")]  
  33. [assembly: AssemblyCulture("")]  
  34.  
  35. // Setting ComVisible to false makes the types in this assembly not visible   
  36. // to COM components.  If you need to access a type in this assembly from   
  37. // COM, set the ComVisible attribute to true on that type.  
  38. [assembly: ComVisible(false)]  
  39.  
  40. // The following GUID is for the ID of the typelib if this project is exposed to COM  
  41. [assembly: Guid("a81cc8df-2751-450a-8406-dac02f97bbb5")]  
  42.  
  43. // Version information for an assembly consists of the following four values:  
  44. //  
  45. //      Major Version  
  46. //      Minor Version   
  47. //      Build Number  
  48. //      Revision  
  49. //  
  50. // You can specify all the values or you can default the Revision and Build Numbers   
  51. // by using the '*' as shown below:  
  52. [assembly: AssemblyVersion("1.0.0.0")]  
  53. [assembly: AssemblyFileVersion("1.0.0.0")] 

Properties\WMAppManifest.xml

 

  1. 代码  
  2.  
  3. <?xml version="1.0" encoding="utf-8"?> 
  4.  
  5. <Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0"> 
  6.   <App xmlns="" ProductID="{67b136af-08e1-473d-8d02-c878debcb8c4}" Title="HelloPhone" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal"  Author="HelloPhone author" Description="Sample description" Publisher="HelloPhone"> 
  7.     <IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath> 
  8.     <Capabilities> 
  9.       <Capability Name="ID_CAP_GAMERSERVICES"/> 
  10.       <Capability Name="ID_CAP_IDENTITY_DEVICE"/> 
  11.       <Capability Name="ID_CAP_IDENTITY_USER"/> 
  12.       <Capability Name="ID_CAP_LOCATION"/> 
  13.       <Capability Name="ID_CAP_MEDIALIB"/> 
  14.       <Capability Name="ID_CAP_MICROPHONE"/> 
  15.       <Capability Name="ID_CAP_NETWORKING"/> 
  16.       <Capability Name="ID_CAP_PHONEDIALER"/> 
  17.       <Capability Name="ID_CAP_PUSH_NOTIFICATION"/> 
  18.       <Capability Name="ID_CAP_SENSORS"/> 
  19.       <Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/> 
  20.     </Capabilities> 
  21.     <Tasks> 
  22.       <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/> 
  23.     </Tasks> 
  24.     <Tokens> 
  25.       <PrimaryToken TokenID="HelloPhoneToken" TaskName="_default"> 
  26.         <TemplateType5> 
  27.           <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI> 
  28.           <Count>0</Count> 
  29.           <Title>HelloPhone</Title> 
  30.         </TemplateType5> 
  31.       </PrimaryToken> 
  32.     </Tokens> 
  33.   </App> 
  34. </Deployment> 

 

Windows Phone 7 hello world _Hello Phone