Windows Phone開發(fā)(4):框架和頁(yè)
http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=0a373422-6680-46a7-89e1-e9a468a14259
上一篇文章中,我們了解了WP應(yīng)用程序的生命周期和各個(gè)事件的觸發(fā)情況,今天,我們一起來(lái)探討一下框架和頁(yè)面。
1、一個(gè)App類,從
Application派生,這跟Silverlight中是一樣的,當(dāng)然,如果你對(duì)Silerlight不熟悉也不要緊,我簡(jiǎn)單吹一下。
我想各位玩過(guò)C#的,不管怎么說(shuō)也應(yīng)該玩過(guò)Windows窗體應(yīng)用程序吧,對(duì),就是我們常說(shuō)的WinForm項(xiàng)目,在WindowsForm項(xiàng)目里面,有一個(gè)Program.cs之類的文件,程序的入口點(diǎn)就在里面定義,在Main的最后,VS默認(rèn)生成的代碼中有這么一行:Application.Run(...);
所以,這個(gè)Application和那個(gè)Application的意義是一樣,專門負(fù)責(zé)整個(gè)應(yīng)用程序范圍的各種事務(wù)的協(xié)調(diào)。
先來(lái)看看頁(yè)面的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">
- ……………………
因?yàn)槌绦蚴敲嫦騑P手機(jī)的,所以注意要使用PhoneApplicationPage而不是用Page類,這樣可以避免出問(wèn)題。Class屬性就是我們這個(gè)頁(yè)面類的類名。
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Orientation屬性就是用來(lái)設(shè)置當(dāng)前頁(yè)面的默認(rèn)方向,是縱向的還是橫向的。