1 // 2 // App.xaml.cpp 3 // Implementation of the App class. 4 // 5 6 #include "pch.h" 7 #include "MainPage.xaml.h" 8 9 using namespace PhoneTutorial; 10 11 using namespace Platform; 12 using namespace Windows::ApplicationModel; 13 using namespace Windows::ApplicationModel::Activation; 14 using namespace Windows::Foundation; 15 using namespace Windows::Foundation::Collections; 16 using namespace Windows::UI::Xaml; 17 using namespace Windows::UI::Xaml::Controls; 18 using namespace Windows::UI::Xaml::Controls::Primitives; 19 using namespace Windows::UI::Xaml::Data; 20 using namespace Windows::UI::Xaml::Input; 21 using namespace Windows::UI::Xaml::Interop; 22 using namespace Windows::UI::Xaml::Media; 23 using namespace Windows::UI::Xaml::Media::Animation; 24 using namespace Windows::UI::Xaml::Navigation; 25 26 // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkID=391641 27 28 /// <summary> 29 /// Initializes the singleton application object. This is the first line of authored code 30 /// executed, and as such is the logical equivalent of main() or WinMain(). 31 /// </summary> 32 App::App() 33 { 34 InitializeComponent(); 35 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); 36 } 37 38 /// <summary> 39 /// Invoked when the application is launched normally by the end user. Other entry points 40 /// will be used when the application is launched to open a specific file, to display 41 /// search results, and so forth. 42 /// </summary> 43 /// <param name="e">Details about the launch request and process.</param> 44 void App::OnLaunched(LaunchActivatedEventArgs^ e) 45 { 46 #if _DEBUG 47 if (IsDebuggerPresent()) 48 { 49 DebugSettings->EnableFrameRateCounter = true; 50 } 51 #endif 52 53 auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content); 54 55 // Do not repeat app initialization when the Window already has content, 56 // just ensure that the window is active. 57 if (rootFrame == nullptr) 58 { 59 // Create a Frame to act as the navigation context and associate it with 60 // a SuspensionManager key 61 rootFrame = ref new Frame(); 62 63 // TODO: Change this value to a cache size that is appropriate for your application. 64 rootFrame->CacheSize = 1; 65 66 if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) 67 { 68 // TODO: Restore the saved session state only when appropriate, scheduling the 69 // final launch steps after the restore is complete. 70 } 71 72 // Place the frame in the current Window 73 Window::Current->Content = rootFrame; 74 } 75 76 if (rootFrame->Content == nullptr) 77 { 78 // Removes the turnstile navigation for startup. 79 if (rootFrame->ContentTransitions != nullptr) 80 { 81 _transitions = ref new TransitionCollection(); 82 for (auto transition : rootFrame->ContentTransitions) 83 { 84 _transitions->Append(transition); 85 } 86 } 87 88 rootFrame->ContentTransitions = nullptr; 89 _firstNavigatedToken = rootFrame->Navigated += ref new NavigatedEventHandler(this, &App::RootFrame_FirstNavigated); 90 91 // When the navigation stack isn't restored navigate to the first page, 92 // configuring the new page by passing required information as a navigation 93 // parameter. 94 if (!rootFrame->Navigate(MainPage::typeid, e->Arguments)) 95 { 96 throw ref new FailureException("Failed to create initial page"); 97 } 98 } 99 100 // Ensure the current window is active 101 Window::Current->Activate(); 102 } 103 104 /// <summary> 105 /// Restores the content transitions after the app has launched. 106 /// </summary> 107 void App::RootFrame_FirstNavigated(Object^ sender, NavigationEventArgs^ e) 108 { 109 auto rootFrame = safe_cast<Frame^>(sender); 110 111 TransitionCollection^ newTransitions; 112 if (_transitions == nullptr) 113 { 114 newTransitions = ref new TransitionCollection(); 115 newTransitions->Append(ref new NavigationThemeTransition()); 116 } 117 else 118 { 119 newTransitions = _transitions; 120 } 121 122 rootFrame->ContentTransitions = newTransitions; 123 rootFrame->Navigated -= _firstNavigatedToken; 124 } 125 126 /// <summary> 127 /// Invoked when application execution is being suspended. Application state is saved 128 /// without knowing whether the application will be terminated or resumed with the contents 129 /// of memory still intact. 130 /// </summary> 131 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e) 132 { 133 (void) sender; // Unused parameter 134 (void) e; // Unused parameter 135 136 // TODO: Save application state and stop any background activity 137 }