PageRenderTime 77ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/MapMarkers/others/mapss/App.xaml.cs

https://bitbucket.org/cjarrett/wp8maasdfaspsexamplessd
C# | 261 lines | 123 code | 38 blank | 100 comment | 17 complexity | 143d6a57d72a0e3d9de4de969ada5dd8 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. /*
  2. * Copyright © 2012 Nokia Corporation. All rights reserved.
  3. * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
  4. * Other product and company names mentioned herein may be trademarks
  5. * or trade names of their respective owners.
  6. * See LICENSE.TXT for license information.
  7. */
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Animation;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. using Microsoft.Phone.Controls;
  21. using Microsoft.Phone.Shell;
  22. using Microsoft.Phone.Maps.Controls;
  23. using System.Diagnostics;
  24. using System.Windows.Markup;
  25. using MapExplorer.Resources;
  26. namespace MapExplorer
  27. {
  28. public partial class App : Application
  29. {
  30. /// <summary>
  31. /// Class variable for Settings property
  32. /// </summary>
  33. private static Settings settings = null;
  34. /// <summary>
  35. /// A static Settings used by the views to bind against.
  36. /// </summary>
  37. /// <returns>The Settings object.</returns>
  38. public static Settings Settings
  39. {
  40. get
  41. {
  42. // Delay creation of the view model until necessary
  43. if (settings == null)
  44. settings = new Settings();
  45. return settings;
  46. }
  47. }
  48. /// <summary>
  49. /// Provides easy access to the root frame of the Phone Application.
  50. /// </summary>
  51. /// <returns>The root frame of the Phone Application.</returns>
  52. public static PhoneApplicationFrame RootFrame { get; private set; }
  53. /// <summary>
  54. /// Constructor for the Application object.
  55. /// </summary>
  56. public App()
  57. {
  58. // Global handler for uncaught exceptions.
  59. UnhandledException += Application_UnhandledException;
  60. // Standard XAML initialization
  61. InitializeComponent();
  62. // Phone-specific initialization
  63. InitializePhoneApplication();
  64. // Language display initialization
  65. InitializeLanguage();
  66. // Show graphics profiling information while debugging.
  67. if (Debugger.IsAttached)
  68. {
  69. // Display the current frame rate counters.
  70. // Application.Current.Host.Settings.EnableFrameRateCounter = true;
  71. // Show the areas of the app that are being redrawn in each frame.
  72. //Application.Current.Host.Settings.EnableRedrawRegions = true;
  73. // Enable non-production analysis visualization mode,
  74. // which shows areas of a page that are handed off to GPU with a colored overlay.
  75. //Application.Current.Host.Settings.EnableCacheVisualization = true;
  76. // Prevent the screen from turning off while under the debugger by disabling
  77. // the application's idle detection.
  78. // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
  79. // and consume battery power when the user is not using the phone.
  80. PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
  81. }
  82. }
  83. // Code to execute when the application is launching (eg, from Start)
  84. // This code will not execute when the application is reactivated
  85. private void Application_Launching(object sender, LaunchingEventArgs e)
  86. {
  87. }
  88. // Code to execute when the application is activated (brought to foreground)
  89. // This code will not execute when the application is first launched
  90. private void Application_Activated(object sender, ActivatedEventArgs e)
  91. {
  92. }
  93. // Code to execute when the application is deactivated (sent to background)
  94. // This code will not execute when the application is closing
  95. private void Application_Deactivated(object sender, DeactivatedEventArgs e)
  96. {
  97. }
  98. // Code to execute when the application is closing (eg, user hit Back)
  99. // This code will not execute when the application is deactivated
  100. private void Application_Closing(object sender, ClosingEventArgs e)
  101. {
  102. }
  103. // Code to execute if a navigation fails
  104. private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
  105. {
  106. if (Debugger.IsAttached)
  107. {
  108. // A navigation has failed; break into the debugger
  109. Debugger.Break();
  110. }
  111. }
  112. // Code to execute on Unhandled Exceptions
  113. private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  114. {
  115. if (Debugger.IsAttached)
  116. {
  117. // An unhandled exception has occurred; break into the debugger
  118. Debugger.Break();
  119. }
  120. }
  121. #region Phone application initialization
  122. // Avoid double-initialization
  123. private bool phoneApplicationInitialized = false;
  124. // Do not add any additional code to this method
  125. private void InitializePhoneApplication()
  126. {
  127. if (phoneApplicationInitialized)
  128. return;
  129. // Create the frame but don't set it as RootVisual yet; this allows the splash
  130. // screen to remain active until the application is ready to render.
  131. RootFrame = new PhoneApplicationFrame();
  132. RootFrame.Navigated += CompleteInitializePhoneApplication;
  133. // Handle navigation failures
  134. RootFrame.NavigationFailed += RootFrame_NavigationFailed;
  135. // Handle reset requests for clearing the backstack
  136. RootFrame.Navigated += CheckForResetNavigation;
  137. // Ensure we don't initialize again
  138. phoneApplicationInitialized = true;
  139. }
  140. // Do not add any additional code to this method
  141. private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
  142. {
  143. // Set the root visual to allow the application to render
  144. if (RootVisual != RootFrame)
  145. RootVisual = RootFrame;
  146. // Remove this handler since it is no longer needed
  147. RootFrame.Navigated -= CompleteInitializePhoneApplication;
  148. }
  149. private void CheckForResetNavigation(object sender, NavigationEventArgs e)
  150. {
  151. // If the app has received a 'reset' navigation, then we need to check
  152. // on the next navigation to see if the page stack should be reset
  153. if (e.NavigationMode == NavigationMode.Reset)
  154. RootFrame.Navigated += ClearBackStackAfterReset;
  155. }
  156. private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
  157. {
  158. // Unregister the event so it doesn't get called again
  159. RootFrame.Navigated -= ClearBackStackAfterReset;
  160. // Only clear the stack for 'new' (forward) and 'refresh' navigations
  161. if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
  162. return;
  163. // For UI consistency, clear the entire page stack
  164. while (RootFrame.RemoveBackEntry() != null)
  165. {
  166. ; // do nothing
  167. }
  168. }
  169. #endregion
  170. // Initialize the app's font and flow direction as defined in its localized resource strings.
  171. //
  172. // To ensure that the font of your application is aligned with its supported languages and that the
  173. // FlowDirection for each of those languages follows its traditional direction, ResourceLanguage
  174. // and ResourceFlowDirection should be initialized in each resx file to match these values with that
  175. // file's culture. For example:
  176. //
  177. // AppResources.es-ES.resx
  178. // ResourceLanguage's value should be "es-ES"
  179. // ResourceFlowDirection's value should be "LeftToRight"
  180. //
  181. // AppResources.ar-SA.resx
  182. // ResourceLanguage's value should be "ar-SA"
  183. // ResourceFlowDirection's value should be "RightToLeft"
  184. //
  185. // For more info on localizing Windows Phone apps see http://go.microsoft.com/fwlink/?LinkId=262072.
  186. //
  187. private void InitializeLanguage()
  188. {
  189. try
  190. {
  191. // Set the font to match the display language defined by the
  192. // ResourceLanguage resource string for each supported language.
  193. //
  194. // Fall back to the font of the neutral language if the Display
  195. // language of the phone is not supported.
  196. //
  197. // If a compiler error is hit then ResourceLanguage is missing from
  198. // the resource file.
  199. RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
  200. // Set the FlowDirection of all elements under the root frame based
  201. // on the ResourceFlowDirection resource string for each
  202. // supported language.
  203. //
  204. // If a compiler error is hit then ResourceFlowDirection is missing from
  205. // the resource file.
  206. FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection);
  207. RootFrame.FlowDirection = flow;
  208. }
  209. catch
  210. {
  211. // If an exception is caught here it is most likely due to either
  212. // ResourceLangauge not being correctly set to a supported language
  213. // code or ResourceFlowDirection is set to a value other than LeftToRight
  214. // or RightToLeft.
  215. if (Debugger.IsAttached)
  216. {
  217. Debugger.Break();
  218. }
  219. throw;
  220. }
  221. }
  222. }
  223. }