App.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Windows.ApplicationModel;
  6. using Windows.ApplicationModel.Activation;
  7. using Windows.Foundation;
  8. using Windows.Foundation.Collections;
  9. using Windows.UI.Xaml;
  10. using Windows.UI.Xaml.Controls;
  11. using Windows.UI.Xaml.Controls.Primitives;
  12. using Windows.UI.Xaml.Data;
  13. using Windows.UI.Xaml.Input;
  14. using Windows.UI.Xaml.Media;
  15. using Windows.UI.Xaml.Navigation;
  16. // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
  17. namespace WindowsStoreApp8_NuGet
  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 when the application is launched to open a specific file, to display
  36. /// search results, and so forth.
  37. /// </summary>
  38. /// <param name="args">Details about the launch request and process.</param>
  39. protected override void OnLaunched(LaunchActivatedEventArgs args)
  40. {
  41. Frame rootFrame = Window.Current.Content as Frame;
  42. // Do not repeat app initialization when the Window already has content,
  43. // just ensure that the window is active
  44. if (rootFrame == null)
  45. {
  46. // Create a Frame to act as the navigation context and navigate to the first page
  47. rootFrame = new Frame();
  48. if (args.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 (rootFrame.Content == null)
  56. {
  57. // When the navigation stack isn't restored navigate to the first page,
  58. // configuring the new page by passing required information as a navigation
  59. // parameter
  60. if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
  61. {
  62. throw new Exception("Failed to create initial page");
  63. }
  64. }
  65. // Ensure the current window is active
  66. Window.Current.Activate();
  67. }
  68. /// <summary>
  69. /// Invoked when application execution is being suspended. Application state is saved
  70. /// without knowing whether the application will be terminated or resumed with the contents
  71. /// of memory still intact.
  72. /// </summary>
  73. /// <param name="sender">The source of the suspend request.</param>
  74. /// <param name="e">Details about the suspend request.</param>
  75. private void OnSuspending(object sender, SuspendingEventArgs e)
  76. {
  77. var deferral = e.SuspendingOperation.GetDeferral();
  78. //TODO: Save application state and stop any background activity
  79. deferral.Complete();
  80. }
  81. }
  82. }