PageRenderTime 32ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/V4/PrismLibrary/Phone/Prism.Interactivity.Tests/App.xaml.cs

#
C# | 124 lines | 61 code | 20 blank | 43 comment | 5 complexity | b8397e73cd1e36fa6e7104c6c64e757f MD5 | raw file
  1//===================================================================================
  2// Microsoft patterns & practices
  3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4//===================================================================================
  5// Copyright (c) Microsoft Corporation.  All rights reserved.
  6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9// FITNESS FOR A PARTICULAR PURPOSE.
 10//===================================================================================
 11// The example companies, organizations, products, domain names,
 12// e-mail addresses, logos, people, places, and events depicted
 13// herein are fictitious.  No association with any real company,
 14// organization, product, domain name, email address, logo, person,
 15// places, or events is intended or should be inferred.
 16//===================================================================================
 17using System.Windows;
 18using System.Windows.Navigation;
 19using Microsoft.Phone.Controls;
 20using Microsoft.Phone.Shell;
 21
 22namespace Microsoft.Practices.Prism.Interactivity.Tests
 23{
 24    public partial class App : Application
 25    {
 26
 27        // Easy access to the root frame
 28        public PhoneApplicationFrame RootFrame { get; private set; }
 29
 30        // Constructor
 31        public App()
 32        {
 33            // Global handler for uncaught exceptions. 
 34            // Note that exceptions thrown by ApplicationBarItem.Click will not get caught here.
 35            UnhandledException += Application_UnhandledException;
 36
 37            // Standard Silverlight initialization
 38            InitializeComponent();
 39
 40            // Phone-specific initialization
 41            InitializePhoneApplication();
 42        }
 43
 44        // Code to execute when the application is launching (eg, from Start)
 45        // This code will not execute when the application is reactivated
 46        private void Application_Launching(object sender, LaunchingEventArgs e)
 47        {
 48        }
 49
 50        // Code to execute when the application is activated (brought to foreground)
 51        // This code will not execute when the application is first launched
 52        private void Application_Activated(object sender, ActivatedEventArgs e)
 53        {
 54        }
 55
 56        // Code to execute when the application is deactivated (sent to background)
 57        // This code will not execute when the application is closing
 58        private void Application_Deactivated(object sender, DeactivatedEventArgs e)
 59        {
 60        }
 61
 62        // Code to execute when the application is closing (eg, user hit Back)
 63        // This code will not execute when the application is deactivated
 64        private void Application_Closing(object sender, ClosingEventArgs e)
 65        {
 66        }
 67
 68        // Code to execute if a navigation fails
 69        void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
 70        {
 71            if (System.Diagnostics.Debugger.IsAttached)
 72            {
 73                // A navigation has failed; break into the debugger
 74                System.Diagnostics.Debugger.Break();
 75            }
 76        }
 77
 78        // Code to execute on Unhandled Exceptions
 79        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
 80        {
 81            if (System.Diagnostics.Debugger.IsAttached)
 82            {
 83                // An unhandled exception has occurred; break into the debugger
 84                System.Diagnostics.Debugger.Break();
 85            }
 86        }
 87
 88        #region Phone application initialization
 89
 90        // Avoid double-initialization
 91        private bool phoneApplicationInitialized = false;
 92
 93        // Do not add any additional code to this method
 94        private void InitializePhoneApplication()
 95        {
 96            if (phoneApplicationInitialized)
 97                return;
 98
 99            // Create the frame but don't set it as RootVisual yet; this allows the splash
100            // screen to remain active until the application is ready to render.
101            RootFrame = new PhoneApplicationFrame();
102            RootFrame.Navigated += CompleteInitializePhoneApplication;
103
104            // Handle navigation failures
105            RootFrame.NavigationFailed += RootFrame_NavigationFailed;
106
107            // Ensure we don't initialize again
108            phoneApplicationInitialized = true;
109        }
110
111        // Do not add any additional code to this method
112        private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
113        {
114            // Set the root visual to allow the application to render
115            if (RootVisual != RootFrame)
116                RootVisual = RootFrame;
117
118            // Remove this handler since it is no longer needed
119            RootFrame.Navigated -= CompleteInitializePhoneApplication;
120        }
121
122        #endregion
123    }
124}