App.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Navigation;
  12. using System.Windows.Shapes;
  13. using Microsoft.Phone.Controls;
  14. using Microsoft.Phone.Shell;
  15. namespace SolitaireHTML5
  16. {
  17. public partial class App : Application
  18. {
  19. /// <summary>
  20. /// Provides easy access to the root frame of the Phone Application.
  21. /// </summary>
  22. /// <returns>The root frame of the Phone Application.</returns>
  23. public PhoneApplicationFrame RootFrame { get; private set; }
  24. /// <summary>
  25. /// Constructor for the Application object.
  26. /// </summary>
  27. public App()
  28. {
  29. // Global handler for uncaught exceptions.
  30. UnhandledException += Application_UnhandledException;
  31. // Standard Silverlight initialization
  32. InitializeComponent();
  33. // Phone-specific initialization
  34. InitializePhoneApplication();
  35. // Show graphics profiling information while debugging.
  36. if (System.Diagnostics.Debugger.IsAttached)
  37. {
  38. // Display the current frame rate counters.
  39. //Application.Current.Host.Settings.EnableFrameRateCounter = true;
  40. // Show the areas of the app that are being redrawn in each frame.
  41. //Application.Current.Host.Settings.EnableRedrawRegions = true;
  42. // Enable non-production analysis visualization mode,
  43. // which shows areas of a page that are handed off to GPU with a colored overlay.
  44. //Application.Current.Host.Settings.EnableCacheVisualization = true;
  45. // Disable the application idle detection by setting the UserIdleDetectionMode property of the
  46. // application's PhoneApplicationService object to Disabled.
  47. // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
  48. // and consume battery power when the user is not using the phone.
  49. PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
  50. }
  51. }
  52. // Code to execute when the application is launching (eg, from Start)
  53. // This code will not execute when the application is reactivated
  54. private void Application_Launching(object sender, LaunchingEventArgs e)
  55. {
  56. }
  57. // Code to execute when the application is activated (brought to foreground)
  58. // This code will not execute when the application is first launched
  59. private void Application_Activated(object sender, ActivatedEventArgs e)
  60. {
  61. }
  62. // Code to execute when the application is deactivated (sent to background)
  63. // This code will not execute when the application is closing
  64. private void Application_Deactivated(object sender, DeactivatedEventArgs e)
  65. {
  66. }
  67. // Code to execute when the application is closing (eg, user hit Back)
  68. // This code will not execute when the application is deactivated
  69. private void Application_Closing(object sender, ClosingEventArgs e)
  70. {
  71. }
  72. // Code to execute if a navigation fails
  73. private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
  74. {
  75. if (System.Diagnostics.Debugger.IsAttached)
  76. {
  77. // A navigation has failed; break into the debugger
  78. System.Diagnostics.Debugger.Break();
  79. }
  80. }
  81. // Code to execute on Unhandled Exceptions
  82. private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  83. {
  84. if (System.Diagnostics.Debugger.IsAttached)
  85. {
  86. // An unhandled exception has occurred; break into the debugger
  87. System.Diagnostics.Debugger.Break();
  88. }
  89. }
  90. #region Phone application initialization
  91. // Avoid double-initialization
  92. private bool phoneApplicationInitialized = false;
  93. // Do not add any additional code to this method
  94. private void InitializePhoneApplication()
  95. {
  96. if (phoneApplicationInitialized)
  97. return;
  98. // Create the frame but don't set it as RootVisual yet; this allows the splash
  99. // screen to remain active until the application is ready to render.
  100. RootFrame = new PhoneApplicationFrame();
  101. RootFrame.Navigated += CompleteInitializePhoneApplication;
  102. // Handle navigation failures
  103. RootFrame.NavigationFailed += RootFrame_NavigationFailed;
  104. // Ensure we don't initialize again
  105. phoneApplicationInitialized = true;
  106. }
  107. // Do not add any additional code to this method
  108. private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
  109. {
  110. // Set the root visual to allow the application to render
  111. if (RootVisual != RootFrame)
  112. RootVisual = RootFrame;
  113. // Remove this handler since it is no longer needed
  114. RootFrame.Navigated -= CompleteInitializePhoneApplication;
  115. }
  116. #endregion
  117. }
  118. }