App.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Diagnostics;
  3. using Windows.ApplicationModel;
  4. using Windows.ApplicationModel.Activation;
  5. using Windows.Phone.UI.Input;
  6. using Windows.UI.Xaml;
  7. using Windows.UI.Xaml.Controls;
  8. using Windows.UI.Xaml.Media.Animation;
  9. using Windows.UI.Xaml.Navigation;
  10. namespace FormulaOneApp.Classic.Windows
  11. {
  12. /// <summary>
  13. /// Proporciona un comportamiento específico de la aplicación para complementar la clase Application predeterminada.
  14. /// </summary>
  15. public sealed partial class App : Application
  16. {
  17. private TransitionCollection transitions;
  18. /// <summary>
  19. /// Inicializa el objeto de aplicación Singleton. Esta es la primera línea de código creado
  20. /// ejecutado y, como tal, es el equivalente lógico de main() o WinMain().
  21. /// </summary>
  22. public App()
  23. {
  24. this.InitializeComponent();
  25. this.Suspending += this.OnSuspending;
  26. HardwareButtons.BackPressed += HardwareButtons_BackPressed;
  27. }
  28. void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
  29. {
  30. Frame frame = Window.Current.Content as Frame;
  31. if (frame == null)
  32. return;
  33. if (frame.CanGoBack)
  34. {
  35. frame.GoBack();
  36. e.Handled = true;
  37. }
  38. }
  39. /// <summary>
  40. /// Se invoca cuando la aplicación la inicia normalmente el usuario final. Se usarán otros puntos
  41. /// de entrada cuando la aplicación se inicie para abrir un archivo específico, para mostrar
  42. /// resultados de la búsqueda, etc.
  43. /// </summary>
  44. /// <param name="e">Información detallada acerca de la solicitud y el proceso de inicio.</param>
  45. protected override void OnLaunched(LaunchActivatedEventArgs args)
  46. {
  47. var rootFrame = Window.Current.Content as Frame;
  48. // Do not repeat app initialization when the Window already has content,
  49. // just ensure that the window is active
  50. if (rootFrame == null)
  51. {
  52. // Create a Frame to act as the navigation context and navigate to the first page
  53. rootFrame = new Frame();
  54. if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
  55. {
  56. //TODO: Load state from previously suspended application
  57. }
  58. // Place the frame in the current Window
  59. Window.Current.Content = rootFrame;
  60. }
  61. if (rootFrame.Content == null)
  62. {
  63. // When the navigation stack isn't restored navigate to the first page,
  64. // configuring the new page by passing required information as a navigation
  65. // parameter
  66. var setup = new Setup(rootFrame);
  67. setup.Initialize();
  68. var start = Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.ViewModels.IMvxAppStart>();
  69. start.Start();
  70. }
  71. // Ensure the current window is active
  72. Window.Current.Activate();
  73. }
  74. /// <summary>
  75. /// Restaura las transiciones de contenido después de iniciar la aplicación.
  76. /// </summary>
  77. /// <param name="sender">Objeto al que se asocia el controlador.</param>
  78. /// <param name="e">Detalles sobre el evento de navegación.</param>
  79. private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
  80. {
  81. var rootFrame = sender as Frame;
  82. rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
  83. rootFrame.Navigated -= this.RootFrame_FirstNavigated;
  84. }
  85. /// <summary>
  86. /// Se invoca al suspender la ejecución de la aplicación. El estado de la aplicación se guarda
  87. /// sin saber si la aplicación se terminará o se reanudará con el contenido
  88. /// de la memoria aún intacto.
  89. /// </summary>
  90. /// <param name="sender">Origen de la solicitud de suspensión.</param>
  91. /// <param name="e">Detalles sobre la solicitud de suspensión.</param>
  92. private void OnSuspending(object sender, SuspendingEventArgs e)
  93. {
  94. var deferral = e.SuspendingOperation.GetDeferral();
  95. // TODO: Guardar el estado de la aplicación y detener toda actividad en segundo plano
  96. deferral.Complete();
  97. }
  98. }
  99. }