Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

82 lignes
3.1 KiB

  1. using System;
  2. using Windows.ApplicationModel;
  3. using Windows.ApplicationModel.Activation;
  4. using Windows.UI.Xaml;
  5. using Windows.UI.Xaml.Controls;
  6. using Windows.UI.Xaml.Navigation;
  7. namespace MQTTnet.TestApp.UniversalWindows
  8. {
  9. sealed partial class App
  10. {
  11. public App()
  12. {
  13. InitializeComponent();
  14. Suspending += OnSuspending;
  15. }
  16. /// <summary>
  17. /// Invoked when the application is launched normally by the end user. Other entry points
  18. /// will be used such as when the application is launched to open a specific file.
  19. /// </summary>
  20. /// <param name="e">Details about the launch request and process.</param>
  21. protected override void OnLaunched(LaunchActivatedEventArgs e)
  22. {
  23. // Do not repeat app initialization when the Window already has content,
  24. // just ensure that the window is active
  25. if (!(Window.Current.Content is Frame rootFrame))
  26. {
  27. // Create a Frame to act as the navigation context and navigate to the first page
  28. rootFrame = new Frame();
  29. rootFrame.NavigationFailed += OnNavigationFailed;
  30. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  31. {
  32. //TODO: Load state from previously suspended application
  33. }
  34. // Place the frame in the current Window
  35. Window.Current.Content = rootFrame;
  36. }
  37. if (e.PrelaunchActivated == false)
  38. {
  39. if (rootFrame.Content == null)
  40. {
  41. // When the navigation stack isn't restored navigate to the first page,
  42. // configuring the new page by passing required information as a navigation
  43. // parameter
  44. rootFrame.Navigate(typeof(MainPage), e.Arguments);
  45. }
  46. // Ensure the current window is active
  47. Window.Current.Activate();
  48. }
  49. }
  50. /// <summary>
  51. /// Invoked when Navigation to a certain page fails
  52. /// </summary>
  53. /// <param name="sender">The Frame which failed navigation</param>
  54. /// <param name="e">Details about the navigation failure</param>
  55. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  56. {
  57. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  58. }
  59. /// <summary>
  60. /// Invoked when application execution is being suspended. Application state is saved
  61. /// without knowing whether the application will be terminated or resumed with the contents
  62. /// of memory still intact.
  63. /// </summary>
  64. /// <param name="sender">The source of the suspend request.</param>
  65. /// <param name="e">Details about the suspend request.</param>
  66. private void OnSuspending(object sender, SuspendingEventArgs e)
  67. {
  68. var deferral = e.SuspendingOperation.GetDeferral();
  69. //TODO: Save application state and stop any background activity
  70. deferral.Complete();
  71. }
  72. }
  73. }