Windows Phone开发(4):框架和页
扫描二维码
随时随地手机看文章
http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=0a373422-6680-46a7-89e1-e9a468a14259
上一篇文章中,我们了解了WP应用程序的生命周期和各个事件的触发情况,今天,我们一起来探讨一下框架和页面。
1、一个App类,从
Application派生,这跟Silverlight中是一样的,当然,如果你对Silerlight不熟悉也不要紧,我简单吹一下。
我想各位玩过C#的,不管怎么说也应该玩过Windows窗体应用程序吧,对,就是我们常说的WinForm项目,在WindowsForm项目里面,有一个Program.cs之类的文件,程序的入口点就在里面定义,在Main的最后,VS默认生成的代码中有这么一行:Application.Run(...);
所以,这个Application和那个Application的意义是一样,专门负责整个应用程序范围的各种事务的协调。
先来看看页面的XAML声明部分。
- <phone:PhoneApplicationPage
- x:Class="phoneApp.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
- xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{StaticResource PhoneForegroundBrush}"
- SupportedOrientations="Portrait" Orientation="Portrait"
- shell:SystemTray.IsVisible="True">
- ……………………
因为程序是面向WP手机的,所以注意要使用PhoneApplicationPage而不是用Page类,这样可以避免出问题。Class属性就是我们这个页面类的类名。
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Orientation属性就是用来设置当前页面的默认方向,是纵向的还是横向的。