App.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using Windows.ApplicationModel;
  3. using Windows.ApplicationModel.Activation;
  4. using Windows.Globalization;
  5. using Windows.UI.Xaml;
  6. using Windows.UI.Xaml.Controls;
  7. using Windows.UI.Xaml.Navigation;
  8. namespace Breda_Tour
  9. {
  10. sealed partial class App : Application
  11. {
  12. #region Languages
  13. private static string _language;
  14. /// <summary>
  15. /// Current languagues: [0] = nl-NL, [1] = en-US
  16. /// </summary>
  17. public static string[] Languages { get; } = { "nl-NL", "en-US" };
  18. /// <summary>
  19. /// Global current language property
  20. /// </summary>
  21. public static string Language {
  22. get {
  23. return _language;
  24. }
  25. set {
  26. _language = value;
  27. if (value == Languages[0])
  28. {
  29. ApplicationLanguages.PrimaryLanguageOverride = "nl-NL";
  30. }
  31. else if (value == Languages[1])
  32. {
  33. ApplicationLanguages.PrimaryLanguageOverride = "en-US";
  34. }
  35. }
  36. }
  37. #endregion
  38. /// <summary>
  39. /// Initializes the singleton application object. This is the first line of authored code
  40. /// executed, and as such is the logical equivalent of main() or WinMain().
  41. /// </summary>
  42. public App()
  43. {
  44. Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
  45. Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
  46. Microsoft.ApplicationInsights.WindowsCollectors.Session);
  47. this.InitializeComponent();
  48. this.Suspending += OnSuspending;
  49. }
  50. /// <summary>
  51. /// Invoked when the application is launched normally by the end user. Other entry points
  52. /// will be used such as when the application is launched to open a specific file.
  53. /// </summary>
  54. /// <param name="e">Details about the launch request and process.</param>
  55. protected override void OnLaunched(LaunchActivatedEventArgs e)
  56. {
  57. //#if DEBUG
  58. // if (System.Diagnostics.Debugger.IsAttached)
  59. // {
  60. // this.DebugSettings.EnableFrameRateCounter = true;
  61. // }
  62. //#endif
  63. Frame rootFrame = Window.Current.Content as Frame;
  64. // Do not repeat app initialization when the Window already has content,
  65. // just ensure that the window is active
  66. if (rootFrame == null)
  67. {
  68. // Create a Frame to act as the navigation context and navigate to the first page
  69. rootFrame = new Frame();
  70. rootFrame.NavigationFailed += OnNavigationFailed;
  71. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  72. {
  73. //TODO: Load state from previously suspended application
  74. }
  75. // Place the frame in the current Window
  76. Window.Current.Content = rootFrame;
  77. }
  78. if (rootFrame.Content == null)
  79. {
  80. // When the navigation stack isn't restored navigate to the first page,
  81. // configuring the new page by passing required information as a navigation
  82. // parameter
  83. rootFrame.Navigate(typeof(SplashScreen.SplashPage), e.Arguments);
  84. }
  85. // Ensure the current window is active
  86. Window.Current.Activate();
  87. }
  88. /// <summary>
  89. /// Invoked when Navigation to a certain page fails
  90. /// </summary>
  91. /// <param name="sender">The Frame which failed navigation</param>
  92. /// <param name="e">Details about the navigation failure</param>
  93. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  94. {
  95. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  96. }
  97. /// <summary>
  98. /// Invoked when application execution is being suspended. Application state is saved
  99. /// without knowing whether the application will be terminated or resumed with the 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. private void OnSuspending(object sender, SuspendingEventArgs e)
  105. {
  106. var deferral = e.SuspendingOperation.GetDeferral();
  107. //TODO: Save application state and stop any background activity
  108. deferral.Complete();
  109. }
  110. }
  111. }