Merge topic 'export-refactor-more-for-cps'
[kiteware-cmake.git] / Tests / VSXaml / App.xaml.cpp
blobf9ae27e60efbc73aef7ec290551a1d2e90ce880e
1 //
2 // App.xaml.cpp
3 // Implementation of the App class.
4 //
6 #include "MainPage.xaml.h"
7 #include "pch.h"
9 using namespace VSXaml;
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;
25 // The Blank Application template is documented at
26 // http://go.microsoft.com/fwlink/?LinkId=234227
28 /// <summary>
29 /// Initializes the singleton application object. This is the first line of
30 /// authored code executed, and as such is the logical equivalent of main()
31 /// or WinMain().
32 /// </summary>
33 App::App()
35 InitializeComponent();
36 Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
39 /// <summary>
40 /// Invoked when the application is launched normally by the end user.
41 /// Other entry points will be used such as when the application is
42 /// launched to open a specific file.
43 /// </summary>
44 /// <param name="e">Details about the launch request and process.</param>
45 void App::OnLaunched(
46 Windows::ApplicationModel::Activation::LaunchActivatedEventArgs ^ e)
49 #if _DEBUG
50 // Show graphics profiling information while debugging.
51 if (IsDebuggerPresent()) {
52 // Display the current frame rate counters
53 DebugSettings->EnableFrameRateCounter = true;
55 #endif
57 auto rootFrame = dynamic_cast<Frame ^>(Window::Current->Content);
59 // Do not repeat app initialization when the Window already has content,
60 // just ensure that the window is active
61 if (rootFrame == nullptr) {
62 // Create a Frame to act as the navigation context and associate it with
63 // a SuspensionManager key
64 rootFrame = ref new Frame();
66 // Set the default language
67 rootFrame->Language =
68 Windows::Globalization::ApplicationLanguages::Languages->GetAt(0);
70 rootFrame->NavigationFailed +=
71 ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(
72 this, &App::OnNavigationFailed);
74 if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) {
75 // TODO: Restore the saved session state only when appropriate,
76 // scheduling the
77 // final launch steps after the restore is complete
80 if (rootFrame->Content == nullptr) {
81 // When the navigation stack isn't restored navigate to the first page,
82 // configuring the new page by passing required information as a
83 // navigation
84 // parameter
85 rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments);
87 // Place the frame in the current Window
88 Window::Current->Content = rootFrame;
89 // Ensure the current window is active
90 Window::Current->Activate();
91 } else {
92 if (rootFrame->Content == nullptr) {
93 // When the navigation stack isn't restored navigate to the first page,
94 // configuring the new page by passing required information as a
95 // navigation
96 // parameter
97 rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments);
99 // Ensure the current window is active
100 Window::Current->Activate();
104 /// <summary>
105 /// Invoked when application execution is being suspended. Application state
106 /// is saved without knowing whether the application will be terminated or
107 /// resumed with the contents of memory still intact.
108 /// </summary>
109 /// <param name="sender">The source of the suspend request.</param>
110 /// <param name="e">Details about the suspend request.</param>
111 void App::OnSuspending(Object ^ sender, SuspendingEventArgs ^ e)
113 (void)sender; // Unused parameter
114 (void)e; // Unused parameter
116 // TODO: Save application state and stop any background activity
119 /// <summary>
120 /// Invoked when Navigation to a certain page fails
121 /// </summary>
122 /// <param name="sender">The Frame which failed navigation</param>
123 /// <param name="e">Details about the navigation failure</param>
124 void App::OnNavigationFailed(
125 Platform::Object ^ sender,
126 Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^ e)
128 throw ref new FailureException("Failed to load Page " +
129 e->SourcePageType.Name);