Windows Phone開發之App檔案講解

來源:互聯網
上載者:User
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    }}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.