App.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 Breda_Tour
  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. /// Global current language property
  26. /// </summary>
  27. public static string Language { get; set; }
  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. public App()
  33. {
  34. Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
  35. Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
  36. Microsoft.ApplicationInsights.WindowsCollectors.Session);
  37. this.InitializeComponent();
  38. this.Suspending += OnSuspending;
  39. }
  40. /// <summary>
  41. /// Invoked when the application is launched normally by the end user. Other entry points
  42. /// will be used such as when the application is launched to open a specific file.
  43. /// </summary>
  44. /// <param name="e">Details about the launch request and process.</param>
  45. protected override void OnLaunched(LaunchActivatedEventArgs e)
  46. {
  47. //#if DEBUG
  48. // if (System.Diagnostics.Debugger.IsAttached)
  49. // {
  50. // this.DebugSettings.EnableFrameRateCounter = true;
  51. // }
  52. //#endif
  53. Frame rootFrame = Window.Current.Content as Frame;
  54. // Do not repeat app initialization when the Window already has content,
  55. // just ensure that the window is active
  56. if (rootFrame == null)
  57. {
  58. // Create a Frame to act as the navigation context and navigate to the first page
  59. rootFrame = new Frame();
  60. rootFrame.NavigationFailed += OnNavigationFailed;
  61. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  62. {
  63. //TODO: Load state from previously suspended application
  64. }
  65. // Place the frame in the current Window
  66. Window.Current.Content = rootFrame;
  67. }
  68. if (rootFrame.Content == null)
  69. {
  70. // When the navigation stack isn't restored navigate to the first page,
  71. // configuring the new page by passing required information as a navigation
  72. // parameter
  73. rootFrame.Navigate(typeof(SplashScreen.SplashPage), e.Arguments);
  74. }
  75. // Ensure the current window is active
  76. Window.Current.Activate();
  77. }
  78. /// <summary>
  79. /// Invoked when Navigation to a certain page fails
  80. /// </summary>
  81. /// <param name="sender">The Frame which failed navigation</param>
  82. /// <param name="e">Details about the navigation failure</param>
  83. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  84. {
  85. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  86. }
  87. /// <summary>
  88. /// Invoked when application execution is being suspended. Application state is saved
  89. /// without knowing whether the application will be terminated or resumed with the contents
  90. /// of memory still intact.
  91. /// </summary>
  92. /// <param name="sender">The source of the suspend request.</param>
  93. /// <param name="e">Details about the suspend request.</param>
  94. private void OnSuspending(object sender, SuspendingEventArgs e)
  95. {
  96. var deferral = e.SuspendingOperation.GetDeferral();
  97. //TODO: Save application state and stop any background activity
  98. deferral.Complete();
  99. }
  100. }
  101. }