No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

101 líneas
3.9 KiB

  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 MQTTnet.TestApp.UniversalWindows
  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. /// Initializes the singleton application object. This is the first line of authored code
  26. /// executed, and as such is the logical equivalent of main() or WinMain().
  27. /// </summary>
  28. public App()
  29. {
  30. this.InitializeComponent();
  31. this.Suspending += OnSuspending;
  32. }
  33. /// <summary>
  34. /// Invoked when the application is launched normally by the end user. Other entry points
  35. /// will be used such as when the application is launched to open a specific file.
  36. /// </summary>
  37. /// <param name="e">Details about the launch request and process.</param>
  38. protected override void OnLaunched(LaunchActivatedEventArgs e)
  39. {
  40. Frame rootFrame = Window.Current.Content as Frame;
  41. // Do not repeat app initialization when the Window already has content,
  42. // just ensure that the window is active
  43. if (rootFrame == null)
  44. {
  45. // Create a Frame to act as the navigation context and navigate to the first page
  46. rootFrame = new Frame();
  47. rootFrame.NavigationFailed += OnNavigationFailed;
  48. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  49. {
  50. //TODO: Load state from previously suspended application
  51. }
  52. // Place the frame in the current Window
  53. Window.Current.Content = rootFrame;
  54. }
  55. if (e.PrelaunchActivated == false)
  56. {
  57. if (rootFrame.Content == null)
  58. {
  59. // When the navigation stack isn't restored navigate to the first page,
  60. // configuring the new page by passing required information as a navigation
  61. // parameter
  62. rootFrame.Navigate(typeof(MainPage), e.Arguments);
  63. }
  64. // Ensure the current window is active
  65. Window.Current.Activate();
  66. }
  67. }
  68. /// <summary>
  69. /// Invoked when Navigation to a certain page fails
  70. /// </summary>
  71. /// <param name="sender">The Frame which failed navigation</param>
  72. /// <param name="e">Details about the navigation failure</param>
  73. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  74. {
  75. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  76. }
  77. /// <summary>
  78. /// Invoked when application execution is being suspended. Application state is saved
  79. /// without knowing whether the application will be terminated or resumed with the contents
  80. /// of memory still intact.
  81. /// </summary>
  82. /// <param name="sender">The source of the suspend request.</param>
  83. /// <param name="e">Details about the suspend request.</param>
  84. private void OnSuspending(object sender, SuspendingEventArgs e)
  85. {
  86. var deferral = e.SuspendingOperation.GetDeferral();
  87. //TODO: Save application state and stop any background activity
  88. deferral.Complete();
  89. }
  90. }
  91. }