App.xaml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. Debug.WriteLine("mijn taal is:" + ApplicationLanguages.ManifestLanguages.First());
  46. }
  47. else if (value == Languages[1])
  48. {
  49. ApplicationLanguages.PrimaryLanguageOverride = "en-US";
  50. Debug.WriteLine("my language is:" + ApplicationLanguages.ManifestLanguages.First());
  51. }
  52. }
  53. }
  54. #endregion
  55. /// <summary>
  56. /// Initializes the singleton application object. This is the first line of authored code
  57. /// executed, and as such is the logical equivalent of main() or WinMain().
  58. /// </summary>
  59. public App()
  60. {
  61. Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
  62. Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
  63. Microsoft.ApplicationInsights.WindowsCollectors.Session);
  64. this.InitializeComponent();
  65. this.Suspending += OnSuspending;
  66. }
  67. /// <summary>
  68. /// Invoked when the application is launched normally by the end user. Other entry points
  69. /// will be used such as when the application is launched to open a specific file.
  70. /// </summary>
  71. /// <param name="e">Details about the launch request and process.</param>
  72. protected override void OnLaunched(LaunchActivatedEventArgs e)
  73. {
  74. //#if DEBUG
  75. // if (System.Diagnostics.Debugger.IsAttached)
  76. // {
  77. // this.DebugSettings.EnableFrameRateCounter = true;
  78. // }
  79. //#endif
  80. Frame rootFrame = Window.Current.Content as Frame;
  81. // Do not repeat app initialization when the Window already has content,
  82. // just ensure that the window is active
  83. if (rootFrame == null)
  84. {
  85. // Create a Frame to act as the navigation context and navigate to the first page
  86. rootFrame = new Frame();
  87. rootFrame.NavigationFailed += OnNavigationFailed;
  88. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  89. {
  90. //TODO: Load state from previously suspended application
  91. }
  92. // Place the frame in the current Window
  93. Window.Current.Content = rootFrame;
  94. }
  95. if (rootFrame.Content == null)
  96. {
  97. // When the navigation stack isn't restored navigate to the first page,
  98. // configuring the new page by passing required information as a navigation
  99. // parameter
  100. rootFrame.Navigate(typeof(SplashScreen.SplashPage), e.Arguments);
  101. }
  102. // Ensure the current window is active
  103. Window.Current.Activate();
  104. }
  105. /// <summary>
  106. /// Invoked when Navigation to a certain page fails
  107. /// </summary>
  108. /// <param name="sender">The Frame which failed navigation</param>
  109. /// <param name="e">Details about the navigation failure</param>
  110. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  111. {
  112. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  113. }
  114. /// <summary>
  115. /// Invoked when application execution is being suspended. Application state is saved
  116. /// without knowing whether the application will be terminated or resumed with the contents
  117. /// of memory still intact.
  118. /// </summary>
  119. /// <param name="sender">The source of the suspend request.</param>
  120. /// <param name="e">Details about the suspend request.</param>
  121. private void OnSuspending(object sender, SuspendingEventArgs e)
  122. {
  123. var deferral = e.SuspendingOperation.GetDeferral();
  124. //TODO: Save application state and stop any background activity
  125. deferral.Complete();
  126. }
  127. }
  128. }