App.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.Media.Animation;
  17. using Windows.UI.Xaml.Navigation;
  18. // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
  19. namespace XamarinFormsGoogleDriveAPI.Windows
  20. {
  21. /// <summary>
  22. /// Provides application-specific behavior to supplement the default Application class.
  23. /// </summary>
  24. public sealed partial class App : Application
  25. {
  26. /// <summary>
  27. /// Initializes the singleton application object. This is the first line of authored code
  28. /// executed, and as such is the logical equivalent of main() or WinMain().
  29. /// </summary>
  30. public App()
  31. {
  32. this.InitializeComponent();
  33. this.Suspending += this.OnSuspending;
  34. }
  35. /// <summary>
  36. /// Invoked when the application is launched normally by the end user. Other entry points
  37. /// will be used when the application is launched to open a specific file, to display
  38. /// search results, and so forth.
  39. /// </summary>
  40. /// <param name="e">Details about the launch request and process.</param>
  41. protected override void OnLaunched(LaunchActivatedEventArgs e)
  42. {
  43. #if DEBUG
  44. if (System.Diagnostics.Debugger.IsAttached)
  45. {
  46. this.DebugSettings.EnableFrameRateCounter = true;
  47. }
  48. #endif
  49. Frame rootFrame = Window.Current.Content as Frame;
  50. // Do not repeat app initialization when the Window already has content,
  51. // just ensure that the window is active
  52. if (rootFrame == null)
  53. {
  54. // Create a Frame to act as the navigation context and navigate to the first page
  55. rootFrame = new Frame();
  56. // TODO: change this value to a cache size that is appropriate for your application
  57. rootFrame.CacheSize = 1;
  58. Xamarin.Forms.Forms.Init(e);
  59. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  60. {
  61. // TODO: Load state from previously suspended application
  62. }
  63. // Place the frame in the current Window
  64. Window.Current.Content = rootFrame;
  65. }
  66. if (rootFrame.Content == null)
  67. {
  68. // When the navigation stack isn't restored navigate to the first page,
  69. // configuring the new page by passing required information as a navigation
  70. // parameter
  71. if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
  72. {
  73. throw new Exception("Failed to create initial page");
  74. }
  75. }
  76. // Ensure the current window is active
  77. Window.Current.Activate();
  78. }
  79. /// <summary>
  80. /// Invoked when application execution is being suspended. Application state is saved
  81. /// without knowing whether the application will be terminated or resumed with the contents
  82. /// of memory still intact.
  83. /// </summary>
  84. /// <param name="sender">The source of the suspend request.</param>
  85. /// <param name="e">Details about the suspend request.</param>
  86. private void OnSuspending(object sender, SuspendingEventArgs e)
  87. {
  88. var deferral = e.SuspendingOperation.GetDeferral();
  89. // TODO: Save application state and stop any background activity
  90. deferral.Complete();
  91. }
  92. }
  93. }