App.xaml.cs 5.0 KB

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