using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Navigation;using System.Windows.Shapes;using Microsoft.Phone.Controls;using Microsoft.Phone.Shell;namespace MicroBlogForWP7{ public partial class App : Application { public PhoneApplicationFrame RootFrame { get; private set; } /// <summary> /// 構造應用程式的對象 /// </summary> public App() { //執行未處理的異常 UnhandledException += Application_UnhandledException; //初始化Silverlight InitializeComponent(); //應用程式特定的初始化 InitializePhoneApplication(); //調試顯示的視圖化資訊 if (System.Diagnostics.Debugger.IsAttached) { //顯示當前的畫面播放速率計數器。 Application.Current.Host.Settings.EnableFrameRateCounter = false; //顯示應用程式正在在每個幀重繪的地區。 Application.Current.Host.Settings.EnableRedrawRegions = false; //允許非生產分析的可視化模式, //這表明,交給了一個彩色套印到GPU的頁面地區。 Application.Current.Host.Settings.EnableCacheVisualization = false; //禁用應用空閑檢測,由設定的UserIdleDetectionMode屬性 //應用的PhoneApplicationService對象為Disabled。 //注意: - 這隻是偵錯模式下使用。禁用使用者空閑檢測的應用程式將繼續運行 //和消耗電池電量,當使用者不使用手機。 PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; } } //要執行的代碼應用程式啟動時(例如,從“開始”) private void Application_Launching(object sender, LaunchingEventArgs e) { } //要執行的代碼的應用程式被啟用時(回到應用程式啟用狀態) private void Application_Activated(object sender, ActivatedEventArgs e) { } //應用程式關閉時要執行的代碼(後台運行失去啟用) private void Application_Deactivated(object sender, DeactivatedEventArgs e) { } //代碼執行應用程式時關閉(例如,使用者關閉) private void Application_Closing(object sender, ClosingEventArgs e) { } //如果導航失敗 private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } } //執行未處理的異常 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } } #region Phone application initialization //避免重複初始化 private bool phoneApplicationInitialized = false; private void InitializePhoneApplication() { if (phoneApplicationInitialized) return; RootFrame = new PhoneApplicationFrame(); RootFrame.Navigated += CompleteInitializePhoneApplication; //處理導航故障 RootFrame.NavigationFailed += RootFrame_NavigationFailed; //確保不再次進行初始化 phoneApplicationInitialized = true; } private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e) { //設定根視覺,以允許應用程式來呈現 if (RootVisual != RootFrame) RootVisual = RootFrame; //不再需要時刪除此處理常式 RootFrame.Navigated -= CompleteInitializePhoneApplication; } #endregion }}