OLD | NEW |
(Empty) | |
| 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 vsixtest; |
| 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::Navigation; |
| 24 |
| 25 /// <summary> |
| 26 /// Initializes the singleton application object. This is the first line of aut
hored code |
| 27 /// executed, and as such is the logical equivalent of main() or WinMain(). |
| 28 /// </summary> |
| 29 App::App() |
| 30 { |
| 31 InitializeComponent(); |
| 32 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); |
| 33 } |
| 34 |
| 35 /// <summary> |
| 36 /// Invoked when the application is launched normally by the end user. Other en
try points |
| 37 /// will be used such as when the application is launched to open a specific fil
e. |
| 38 /// </summary> |
| 39 /// <param name="e">Details about the launch request and process.</param> |
| 40 void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent
Args^ e) |
| 41 { |
| 42 |
| 43 #if _DEBUG |
| 44 // Show graphics profiling information while debugging. |
| 45 if (IsDebuggerPresent()) |
| 46 { |
| 47 // Display the current frame rate counters |
| 48 DebugSettings->EnableFrameRateCounter = true; |
| 49 } |
| 50 #endif |
| 51 |
| 52 auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content); |
| 53 |
| 54 // Do not repeat app initialization when the Window already has content, |
| 55 // just ensure that the window is active |
| 56 if (rootFrame == nullptr) |
| 57 { |
| 58 // Create a Frame to act as the navigation context and associate
it with |
| 59 // a SuspensionManager key |
| 60 rootFrame = ref new Frame(); |
| 61 |
| 62 rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Naviga
tion::NavigationFailedEventHandler(this, &App::OnNavigationFailed); |
| 63 |
| 64 if (e->PreviousExecutionState == ApplicationExecutionState::Term
inated) |
| 65 { |
| 66 // TODO: Restore the saved session state only when appro
priate, scheduling the |
| 67 // final launch steps after the restore is complete |
| 68 |
| 69 } |
| 70 |
| 71 if (rootFrame->Content == nullptr) |
| 72 { |
| 73 // When the navigation stack isn't restored navigate to
the first page, |
| 74 // configuring the new page by passing required informat
ion as a navigation |
| 75 // parameter |
| 76 rootFrame->Navigate(TypeName(MainPage::typeid), e->Argum
ents); |
| 77 } |
| 78 // Place the frame in the current Window |
| 79 Window::Current->Content = rootFrame; |
| 80 // Ensure the current window is active |
| 81 Window::Current->Activate(); |
| 82 } |
| 83 else |
| 84 { |
| 85 if (rootFrame->Content == nullptr) |
| 86 { |
| 87 // When the navigation stack isn't restored navigate to
the first page, |
| 88 // configuring the new page by passing required informat
ion as a navigation |
| 89 // parameter |
| 90 rootFrame->Navigate(TypeName(MainPage::typeid), e->Argum
ents); |
| 91 } |
| 92 // Ensure the current window is active |
| 93 Window::Current->Activate(); |
| 94 } |
| 95 } |
| 96 |
| 97 /// <summary> |
| 98 /// Invoked when application execution is being suspended. Application stat
e is saved |
| 99 /// without knowing whether the application will be terminated or resumed with t
he contents |
| 100 /// of memory still intact. |
| 101 /// </summary> |
| 102 /// <param name="sender">The source of the suspend request.</param> |
| 103 /// <param name="e">Details about the suspend request.</param> |
| 104 void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e) |
| 105 { |
| 106 (void) sender; // Unused parameter |
| 107 (void) e; // Unused parameter |
| 108 |
| 109 //TODO: Save application state and stop any background activity |
| 110 } |
| 111 |
| 112 /// <summary> |
| 113 /// Invoked when Navigation to a certain page fails |
| 114 /// </summary> |
| 115 /// <param name="sender">The Frame which failed navigation</param> |
| 116 /// <param name="e">Details about the navigation failure</param> |
| 117 void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Naviga
tion::NavigationFailedEventArgs ^e) |
| 118 { |
| 119 throw ref new FailureException("Failed to load Page " + e->SourcePageTyp
e.Name); |
| 120 } |
OLD | NEW |