App.xaml.cs 5.0 KB

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