|
| 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 | + |
| 17 | +// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227 |
| 18 | + |
| 19 | +namespace PlanetsListBox |
| 20 | +{ |
| 21 | + /// <summary> |
| 22 | + /// Provides application-specific behavior to supplement the default Application class. |
| 23 | + /// </summary> |
| 24 | + 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 += OnSuspending; |
| 34 | + } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Invoked when the application is launched normally by the end user. Other entry points |
| 38 | + /// will be used when the application is launched to open a specific file, to display |
| 39 | + /// search results, and so forth. |
| 40 | + /// </summary> |
| 41 | + /// <param name="args">Details about the launch request and process.</param> |
| 42 | + protected override void OnLaunched(LaunchActivatedEventArgs args) |
| 43 | + { |
| 44 | + Frame rootFrame = Window.Current.Content as Frame; |
| 45 | + |
| 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 | + |
| 53 | + if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) |
| 54 | + { |
| 55 | + //TODO: Load state from previously suspended application |
| 56 | + } |
| 57 | + |
| 58 | + // Place the frame in the current Window |
| 59 | + Window.Current.Content = rootFrame; |
| 60 | + } |
| 61 | + |
| 62 | + if (rootFrame.Content == null) |
| 63 | + { |
| 64 | + // When the navigation stack isn't restored navigate to the first page, |
| 65 | + // configuring the new page by passing required information as a navigation |
| 66 | + // parameter |
| 67 | + if (!rootFrame.Navigate(typeof(MainPage), args.Arguments)) |
| 68 | + { |
| 69 | + throw new Exception("Failed to create initial page"); |
| 70 | + } |
| 71 | + } |
| 72 | + // Ensure the current window is active |
| 73 | + Window.Current.Activate(); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Invoked when application execution is being suspended. Application state is saved |
| 78 | + /// without knowing whether the application will be terminated or resumed with the contents |
| 79 | + /// of memory still intact. |
| 80 | + /// </summary> |
| 81 | + /// <param name="sender">The source of the suspend request.</param> |
| 82 | + /// <param name="e">Details about the suspend request.</param> |
| 83 | + private void OnSuspending(object sender, SuspendingEventArgs e) |
| 84 | + { |
| 85 | + var deferral = e.SuspendingOperation.GetDeferral(); |
| 86 | + //TODO: Save application state and stop any background activity |
| 87 | + deferral.Complete(); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments