App.xaml.cs 4.4 KB

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