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