App.xaml.cs 5.9 KB

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