PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/PrismLibrary/Phone/Prism.Interactivity.Tests/App.xaml.cs

#
C# | 124 lines | 61 code | 20 blank | 43 comment | 5 complexity | b8397e73cd1e36fa6e7104c6c64e757f MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System.Windows;
  18. using System.Windows.Navigation;
  19. using Microsoft.Phone.Controls;
  20. using Microsoft.Phone.Shell;
  21. namespace Microsoft.Practices.Prism.Interactivity.Tests
  22. {
  23. public partial class App : Application
  24. {
  25. // Easy access to the root frame
  26. public PhoneApplicationFrame RootFrame { get; private set; }
  27. // Constructor
  28. public App()
  29. {
  30. // Global handler for uncaught exceptions.
  31. // Note that exceptions thrown by ApplicationBarItem.Click will not get caught here.
  32. UnhandledException += Application_UnhandledException;
  33. // Standard Silverlight initialization
  34. InitializeComponent();
  35. // Phone-specific initialization
  36. InitializePhoneApplication();
  37. }
  38. // Code to execute when the application is launching (eg, from Start)
  39. // This code will not execute when the application is reactivated
  40. private void Application_Launching(object sender, LaunchingEventArgs e)
  41. {
  42. }
  43. // Code to execute when the application is activated (brought to foreground)
  44. // This code will not execute when the application is first launched
  45. private void Application_Activated(object sender, ActivatedEventArgs e)
  46. {
  47. }
  48. // Code to execute when the application is deactivated (sent to background)
  49. // This code will not execute when the application is closing
  50. private void Application_Deactivated(object sender, DeactivatedEventArgs e)
  51. {
  52. }
  53. // Code to execute when the application is closing (eg, user hit Back)
  54. // This code will not execute when the application is deactivated
  55. private void Application_Closing(object sender, ClosingEventArgs e)
  56. {
  57. }
  58. // Code to execute if a navigation fails
  59. void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
  60. {
  61. if (System.Diagnostics.Debugger.IsAttached)
  62. {
  63. // A navigation has failed; break into the debugger
  64. System.Diagnostics.Debugger.Break();
  65. }
  66. }
  67. // Code to execute on Unhandled Exceptions
  68. private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  69. {
  70. if (System.Diagnostics.Debugger.IsAttached)
  71. {
  72. // An unhandled exception has occurred; break into the debugger
  73. System.Diagnostics.Debugger.Break();
  74. }
  75. }
  76. #region Phone application initialization
  77. // Avoid double-initialization
  78. private bool phoneApplicationInitialized = false;
  79. // Do not add any additional code to this method
  80. private void InitializePhoneApplication()
  81. {
  82. if (phoneApplicationInitialized)
  83. return;
  84. // Create the frame but don't set it as RootVisual yet; this allows the splash
  85. // screen to remain active until the application is ready to render.
  86. RootFrame = new PhoneApplicationFrame();
  87. RootFrame.Navigated += CompleteInitializePhoneApplication;
  88. // Handle navigation failures
  89. RootFrame.NavigationFailed += RootFrame_NavigationFailed;
  90. // Ensure we don't initialize again
  91. phoneApplicationInitialized = true;
  92. }
  93. // Do not add any additional code to this method
  94. private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
  95. {
  96. // Set the root visual to allow the application to render
  97. if (RootVisual != RootFrame)
  98. RootVisual = RootFrame;
  99. // Remove this handler since it is no longer needed
  100. RootFrame.Navigated -= CompleteInitializePhoneApplication;
  101. }
  102. #endregion
  103. }
  104. }