PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/App.xaml.cs

https://gitlab.com/yann510/Memory-game
C# | 108 lines | 63 code | 11 blank | 34 comment | 7 complexity | 62ed2e2959216a7a4560139eb2a988d8 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.InteropServices.WindowsRuntime;
  6. using Windows.ApplicationModel;
  7. using Windows.ApplicationModel.Activation;
  8. using Windows.Foundation;
  9. using Windows.Foundation.Collections;
  10. using Windows.UI.Xaml;
  11. using Windows.UI.Xaml.Controls;
  12. using Windows.UI.Xaml.Controls.Primitives;
  13. using Windows.UI.Xaml.Data;
  14. using Windows.UI.Xaml.Input;
  15. using Windows.UI.Xaml.Media;
  16. using Windows.UI.Xaml.Navigation;
  17. namespace AppMajorChallenge4
  18. {
  19. /// <summary>
  20. /// Provides application-specific behavior to supplement the default Application class.
  21. /// </summary>
  22. sealed partial class App : Application
  23. {
  24. /// <summary>
  25. /// Initializes the singleton application object. This is the first line of authored code
  26. /// executed, and as such is the logical equivalent of main() or WinMain().
  27. /// </summary>
  28. public App()
  29. {
  30. Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
  31. Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
  32. Microsoft.ApplicationInsights.WindowsCollectors.Session);
  33. this.InitializeComponent();
  34. this.Suspending += OnSuspending;
  35. }
  36. /// <summary>
  37. /// Invoked when the application is launched normally by the end user. Other entry points
  38. /// will be used such as when the application is launched to open a specific file.
  39. /// </summary>
  40. /// <param name="e">Details about the launch request and process.</param>
  41. protected override void OnLaunched(LaunchActivatedEventArgs e)
  42. {
  43. #if DEBUG
  44. if (System.Diagnostics.Debugger.IsAttached)
  45. {
  46. this.DebugSettings.EnableFrameRateCounter = true;
  47. }
  48. #endif
  49. Frame rootFrame = Window.Current.Content as Frame;
  50. // Do not repeat app initialization when the Window already has content,
  51. // just ensure that the window is active
  52. if (rootFrame == null)
  53. {
  54. // Create a Frame to act as the navigation context and navigate to the first page
  55. rootFrame = new Frame();
  56. rootFrame.NavigationFailed += OnNavigationFailed;
  57. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  58. {
  59. //TODO: Load state from previously suspended application
  60. }
  61. // Place the frame in the current Window
  62. Window.Current.Content = rootFrame;
  63. }
  64. if (rootFrame.Content == null)
  65. {
  66. // When the navigation stack isn't restored navigate to the first page,
  67. // configuring the new page by passing required information as a navigation
  68. // parameter
  69. rootFrame.Navigate(typeof(MainPage), e.Arguments);
  70. }
  71. // Ensure the current window is active
  72. Window.Current.Activate();
  73. }
  74. /// <summary>
  75. /// Invoked when Navigation to a certain page fails
  76. /// </summary>
  77. /// <param name="sender">The Frame which failed navigation</param>
  78. /// <param name="e">Details about the navigation failure</param>
  79. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  80. {
  81. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  82. }
  83. /// <summary>
  84. /// Invoked when application execution is being suspended. Application state is saved
  85. /// without knowing whether the application will be terminated or resumed with the contents
  86. /// of memory still intact.
  87. /// </summary>
  88. /// <param name="sender">The source of the suspend request.</param>
  89. /// <param name="e">Details about the suspend request.</param>
  90. private void OnSuspending(object sender, SuspendingEventArgs e)
  91. {
  92. var deferral = e.SuspendingOperation.GetDeferral();
  93. //TODO: Save application state and stop any background activity
  94. deferral.Complete();
  95. }
  96. }
  97. }