直接離開App的方法

摘要:直接離開App的方法

在silverlight windows phone裡,要直接離開App的方式微軟並沒有提供,我是用比較直接的方式,不知道審核會不會通過就是....XD
 

先使用


NavigationService.Navigate(new Uri("/NotExistPage", UriKind.Relative));

當然,這個會在VS的Exception會出現警告,所以我們對Exception做些處理,在App.xaml裡


       // 巡覽失敗時要執行的程式碼
        private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            // 放絕招
            if (e.Exception.Message == "No XAML was found at the location '/NotExistPage'.")
                return;
                
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // 巡覽失敗; 切換到偵錯工具
                System.Diagnostics.Debugger.Break();
            }
        }
        // 發生未處理的例外狀況時要執行的程式碼
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // 放絕招
            if (e.ExceptionObject.Message == "No XAML was found at the location '/NotExistPage'.")
                return;

            if (System.Diagnostics.Debugger.IsAttached)
            {
                // 發生未處理的例外狀況; 切換到偵錯工具
                System.Diagnostics.Debugger.Break();
            }
        }

因為字串是固定的,所以直接去判斷就可以了,不知道到時能不能審核通過哩...囧