Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  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. #if WINDOWS_PHONE_APP
  19. using Windows.Phone.UI.Input;
  20. #endif
  21. // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
  22.  
  23. namespace RememberMe
  24. {
  25.     /// <summary>
  26.     /// Provides application-specific behavior to supplement the default Application class.
  27.     /// </summary>
  28.     public sealed partial class App : Application
  29.     {
  30. #if WINDOWS_PHONE_APP
  31.         private TransitionCollection transitions;
  32. #endif
  33.  
  34.         /// <summary>
  35.         /// Initializes the singleton application object.  This is the first line of authored code
  36.         /// executed, and as such is the logical equivalent of main() or WinMain().
  37.         /// </summary>
  38.         public App()
  39.         {
  40.             this.InitializeComponent();
  41.             this.Suspending += this.OnSuspending;
  42. #if WINDOWS_PHONE_APP
  43.             HardwareButtons.BackPressed += HardwareButtons_BackPressed;
  44. #endif
  45.         }
  46. #if WINDOWS_PHONE_APP
  47.         void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
  48.         {
  49.             Frame rootFrame = Window.Current.Content as Frame;
  50.             if (rootFrame != null && rootFrame.CanGoBack)
  51.             {
  52.                 e.Handled = true;
  53.                 rootFrame.GoBack();
  54.             }
  55.         }
  56. #endif
  57.         /// <summary>
  58.         /// Invoked when the application is launched normally by the end user.  Other entry points
  59.         /// will be used when the application is launched to open a specific file, to display
  60.         /// search results, and so forth.
  61.         /// </summary>
  62.         /// <param name="e">Details about the launch request and process.</param>
  63.         protected override void OnLaunched(LaunchActivatedEventArgs e)
  64.         {
  65. #if DEBUG
  66.             if (System.Diagnostics.Debugger.IsAttached)
  67.             {
  68.                 this.DebugSettings.EnableFrameRateCounter = true;
  69.             }
  70. #endif
  71.  
  72.             Frame rootFrame = Window.Current.Content as Frame;
  73.  
  74.             // Do not repeat app initialization when the Window already has content,
  75.             // just ensure that the window is active
  76.             if (rootFrame == null)
  77.             {
  78.                 // Create a Frame to act as the navigation context and navigate to the first page
  79.                 rootFrame = new Frame();
  80.  
  81.                 // TODO: change this value to a cache size that is appropriate for your application
  82.                 rootFrame.CacheSize = 1;
  83.  
  84.                 if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  85.                 {
  86.                     // TODO: Load state from previously suspended application
  87.                 }
  88.  
  89.                 // Place the frame in the current Window
  90.                 Window.Current.Content = rootFrame;
  91.             }
  92.  
  93.             if (rootFrame.Content == null)
  94.             {
  95. #if WINDOWS_PHONE_APP
  96.                 // Removes the turnstile navigation for startup.
  97.                 if (rootFrame.ContentTransitions != null)
  98.                 {
  99.                     this.transitions = new TransitionCollection();
  100.                     foreach (var c in rootFrame.ContentTransitions)
  101.                     {
  102.                         this.transitions.Add(c);
  103.                     }
  104.                 }
  105.  
  106.                 rootFrame.ContentTransitions = null;
  107.                 rootFrame.Navigated += this.RootFrame_FirstNavigated;
  108. #endif
  109.  
  110.                 // When the navigation stack isn't restored navigate to the first page,
  111.                 // configuring the new page by passing required information as a navigation
  112.                 // parameter
  113.                 if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
  114.                 {
  115.                     throw new Exception("Failed to create initial page");
  116.                 }
  117.             }
  118.  
  119.             // Ensure the current window is active
  120.             Window.Current.Activate();
  121.         }
  122.  
  123. #if WINDOWS_PHONE_APP
  124.         /// <summary>
  125.         /// Restores the content transitions after the app has launched.
  126.         /// </summary>
  127.         /// <param name="sender">The object where the handler is attached.</param>
  128.         /// <param name="e">Details about the navigation event.</param>
  129.         private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
  130.         {
  131.             var rootFrame = sender as Frame;
  132.             rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
  133.             rootFrame.Navigated -= this.RootFrame_FirstNavigated;
  134.         }
  135. #endif
  136.  
  137.         /// <summary>
  138.         /// Invoked when application execution is being suspended.  Application state is saved
  139.         /// without knowing whether the application will be terminated or resumed with the contents
  140.         /// of memory still intact.
  141.         /// </summary>
  142.         /// <param name="sender">The source of the suspend request.</param>
  143.         /// <param name="e">Details about the suspend request.</param>
  144.         private void OnSuspending(object sender, SuspendingEventArgs e)
  145.         {
  146.             var deferral = e.SuspendingOperation.GetDeferral();
  147.  
  148.             // TODO: Save application state and stop any background activity
  149.             deferral.Complete();
  150.         }
  151.     }
  152. }