1、Windows Phone 8目前支援3種螢幕分辨率,分别是
WVGA 800X480 (15:9)
WXGA 1280X768 (15:9)
720p 1280X720 (16:9)
2、在Windows Phone 8中,當BackgroundAudioPlayer的狀态更改時,可以從PlayStateChangedEventArgs中捕獲有關狀态改變的資訊。
3、要使頁面支援旋轉,要把PhoneApplicationPage的SupportedOrientations屬性改為PortraitOrLandscape,然後可以通過定義OrientationChanged事件來處理布局。
<phone:PhoneApplicationPage
...
SupportedOrientations="PortraitOrLandscape"
Orientation="Portrait"
OrientationChanged="PhoneApplicationPage_OrientationChanged">
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
MessageBox.Show("螢幕發生旋轉,目前是:" + e.Orientation);
// 如果是橫向的
if (e.Orientation == PageOrientation.Landscape ||
e.Orientation == PageOrientation.LandscapeLeft ||
e.Orientation == PageOrientation.LandscapeRight)
{
Grid.SetColumn(this.img, 0);
Grid.SetRow(this.img, 0);
Grid.SetRow(this.txtBlock, 0);
Grid.SetColumn(this.txtBlock, 1);
}
// 如果是縱向
else if (e.Orientation == PageOrientation.Portrait ||
e.Orientation == PageOrientation.PortraitDown ||
e.Orientation == PageOrientation.PortraitUp)
Grid.SetRow(this.txtBlock, 1);
Grid.SetColumn(this.txtBlock, 0);
else
}
狀态有PortraitUp、LandscapeLeft、LandscapeRight
4、文本顯示控件TextBlock,裡面文字顯示不同顔色,通過<Run Foreground="Red">Windows Phone 8</Run>标簽實作,文字中間換行,使用<LineBreak/> 标記,如下:
<TextBlock x:Name="txtBlock"
FontSize="70"
Margin="28">
<Run Foreground="Coral">Hello Kitty!</Run>
<LineBreak/>
<Run Foreground="Yellow">Windows Phone 8</Run>
<Run Foreground="SkyBlue">WebGIS</Run>
</TextBlock>
5、頁導航
<HyperlinkButton Content="跳到頁面二" Height="78" HorizontalAlignment="Left" Margin="126,86,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="216" FontSize="32" FontStyle="Normal" FontStretch="Normal"
NavigateUri="/pageSecond.xaml"/>
private void button1_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/pageSecond.xaml", UriKind.Relative));
}
6、OnNavigatedFrom 方法和OnNavigatedTo 方法。
1)、當使用者即将離開目前頁時,将調用OnNavigatedFrom 方法;
2)、當使用者從其它頁面導航到該頁面時調用OnNavigatedTo 方法。
// 離開首頁面
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
base.OnNavigatedFrom(e);
System.Diagnostics.Debug.WriteLine("***** 已離開首頁面。");
}
// 導航到第二個頁面
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
base.OnNavigatedTo(e);
System.Diagnostics.Debug.WriteLine("***** Hi,已經來到第二個頁面了。");
7、頁之間傳遞參數
this.NavigationService.Navigate(new Uri("/pageSecond.xaml?str=" + textBox1.Text, UriKind.Relative));
// 導航到第二個頁面
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
base.OnNavigatedTo(e);
// 傳遞的參數叫什麼名字,這裡就按什麼名字來取。
string pv = this.NavigationContext.QueryString["str"];
this.textBlock1.Text = pv;
}
8、如何屏蔽掉“回退”按鈕?
這種情況下不多見,屏蔽掉回退按鈕意味着無法通過按下“回退”進行向後導航,這個做法要慎用。
要完成該操作,就得處理BackKeyPress事件,把事件參數e的Cancel屬性設定為true即可取消“回退”鍵的操作。
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
base.OnBackKeyPress(e);
e.Cancel = true;
9、如何删除導航曆史記錄?
比如說,我現在從首頁導航到頁面B,再從頁面B導航到頁面C,但我不希望使用者導航回頁面B,而是直接導航回首頁。
我們要在導航的回退曆史記錄中删除頁面B,是以,我們在離開頁面B後把曆史記錄删除。也就是說,在頁面B中重寫OnNavigatedFrom方法。
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
PhoneApplicationFrame myFrame = Application.Current.RootVisual as PhoneApplicationFrame;
if (myFrame != null)
{
try
{
myFrame.RemoveBackEntry();
}
catch (InvalidOperationException ex)
MessageBox.Show(ex.Message);
}
}
從例子中看到,使用PhoneApplicationFrame類的RemoveBackEntry方法删除最新一條記錄,每次隻删除一條,要删除多條,就調用N次。因為導航曆史記錄是棧結構的,後進先出,是以,就像你拿一堆書放在桌面上一樣,首先拿掉的是放在最上面的,如下圖所示:

10、使用State儲存頁面的暫态資料
在頁面填寫資料的