| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- using System.Diagnostics;
- using Windows.ApplicationModel;
- using Windows.ApplicationModel.Activation;
- using Windows.Phone.UI.Input;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Media.Animation;
- using Windows.UI.Xaml.Navigation;
- namespace FormulaOneApp.Classic.Windows
- {
- /// <summary>
- /// Proporciona un comportamiento específico de la aplicación para complementar la clase Application predeterminada.
- /// </summary>
- public sealed partial class App : Application
- {
- private TransitionCollection transitions;
- /// <summary>
- /// Inicializa el objeto de aplicación Singleton. Esta es la primera línea de código creado
- /// ejecutado y, como tal, es el equivalente lógico de main() o WinMain().
- /// </summary>
- public App()
- {
- this.InitializeComponent();
- this.Suspending += this.OnSuspending;
- HardwareButtons.BackPressed += HardwareButtons_BackPressed;
- }
- void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
- {
- Frame frame = Window.Current.Content as Frame;
- if (frame == null)
- return;
- if (frame.CanGoBack)
- {
- frame.GoBack();
- e.Handled = true;
- }
- }
- /// <summary>
- /// Se invoca cuando la aplicación la inicia normalmente el usuario final. Se usarán otros puntos
- /// de entrada cuando la aplicación se inicie para abrir un archivo específico, para mostrar
- /// resultados de la búsqueda, etc.
- /// </summary>
- /// <param name="e">Información detallada acerca de la solicitud y el proceso de inicio.</param>
- protected override void OnLaunched(LaunchActivatedEventArgs args)
- {
- var rootFrame = Window.Current.Content as Frame;
- // Do not repeat app initialization when the Window already has content,
- // just ensure that the window is active
- if (rootFrame == null)
- {
- // Create a Frame to act as the navigation context and navigate to the first page
- rootFrame = new Frame();
- if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
- {
- //TODO: Load state from previously suspended application
- }
- // Place the frame in the current Window
- Window.Current.Content = rootFrame;
- }
- if (rootFrame.Content == null)
- {
- // When the navigation stack isn't restored navigate to the first page,
- // configuring the new page by passing required information as a navigation
- // parameter
- var setup = new Setup(rootFrame);
- setup.Initialize();
- var start = Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.ViewModels.IMvxAppStart>();
- start.Start();
- }
- // Ensure the current window is active
- Window.Current.Activate();
- }
- /// <summary>
- /// Restaura las transiciones de contenido después de iniciar la aplicación.
- /// </summary>
- /// <param name="sender">Objeto al que se asocia el controlador.</param>
- /// <param name="e">Detalles sobre el evento de navegación.</param>
- private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
- {
- var rootFrame = sender as Frame;
- rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
- rootFrame.Navigated -= this.RootFrame_FirstNavigated;
- }
- /// <summary>
- /// Se invoca al suspender la ejecución de la aplicación. El estado de la aplicación se guarda
- /// sin saber si la aplicación se terminará o se reanudará con el contenido
- /// de la memoria aún intacto.
- /// </summary>
- /// <param name="sender">Origen de la solicitud de suspensión.</param>
- /// <param name="e">Detalles sobre la solicitud de suspensión.</param>
- private void OnSuspending(object sender, SuspendingEventArgs e)
- {
- var deferral = e.SuspendingOperation.GetDeferral();
- // TODO: Guardar el estado de la aplicación y detener toda actividad en segundo plano
- deferral.Complete();
- }
- }
- }
|