2
using System.Diagnostics;
3
using System.Resources;
5
using System.Windows.Markup;
6
using System.Windows.Navigation;
7
using Microsoft.Phone.Controls;
8
using Microsoft.Phone.Shell;
9
using PhoneXamlDirect3DApp1.Resources;
11
namespace PhoneXamlDirect3DApp1
13
public partial class App : Application
16
/// Provides easy access to the root frame of the Phone Application.
18
/// <returns>The root frame of the Phone Application.</returns>
19
public static PhoneApplicationFrame RootFrame { get; private set; }
22
/// Constructor for the Application object.
26
// Global handler for uncaught exceptions.
27
UnhandledException += Application_UnhandledException;
29
// Standard XAML initialization
30
InitializeComponent();
32
// Phone-specific initialization
33
InitializePhoneApplication();
35
// Language display initialization
38
// Show graphics profiling information while debugging.
39
if (Debugger.IsAttached)
41
// Display the current frame rate counters.
42
Application.Current.Host.Settings.EnableFrameRateCounter = true;
44
// Show the areas of the app that are being redrawn in each frame.
45
//Application.Current.Host.Settings.EnableRedrawRegions = true;
47
// Enable non-production analysis visualization mode,
48
// which shows areas of a page that are handed off to GPU with a colored overlay.
49
//Application.Current.Host.Settings.EnableCacheVisualization = true;
51
// Prevent the screen from turning off while under the debugger by disabling
52
// the application's idle detection.
53
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
54
// and consume battery power when the user is not using the phone.
55
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
60
// Code to execute when the application is launching (eg, from Start)
61
// This code will not execute when the application is reactivated
62
private void Application_Launching(object sender, LaunchingEventArgs e)
66
// Code to execute when the application is activated (brought to foreground)
67
// This code will not execute when the application is first launched
68
private void Application_Activated(object sender, ActivatedEventArgs e)
72
// Code to execute when the application is deactivated (sent to background)
73
// This code will not execute when the application is closing
74
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
78
// Code to execute when the application is closing (eg, user hit Back)
79
// This code will not execute when the application is deactivated
80
private void Application_Closing(object sender, ClosingEventArgs e)
84
// Code to execute if a navigation fails
85
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
87
if (Debugger.IsAttached)
89
// A navigation has failed; break into the debugger
94
// Code to execute on Unhandled Exceptions
95
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
97
if (Debugger.IsAttached)
99
// An unhandled exception has occurred; break into the debugger
104
#region Phone application initialization
106
// Avoid double-initialization
107
private bool phoneApplicationInitialized = false;
109
// Do not add any additional code to this method
110
private void InitializePhoneApplication()
112
if (phoneApplicationInitialized)
115
// Create the frame but don't set it as RootVisual yet; this allows the splash
116
// screen to remain active until the application is ready to render.
117
RootFrame = new PhoneApplicationFrame();
118
RootFrame.Navigated += CompleteInitializePhoneApplication;
120
// Handle navigation failures
121
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
123
// Handle reset requests for clearing the backstack
124
RootFrame.Navigated += CheckForResetNavigation;
126
// Ensure we don't initialize again
127
phoneApplicationInitialized = true;
130
// Do not add any additional code to this method
131
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
133
// Set the root visual to allow the application to render
134
if (RootVisual != RootFrame)
135
RootVisual = RootFrame;
137
// Remove this handler since it is no longer needed
138
RootFrame.Navigated -= CompleteInitializePhoneApplication;
141
private void CheckForResetNavigation(object sender, NavigationEventArgs e)
143
// If the app has received a 'reset' navigation, then we need to check
144
// on the next navigation to see if the page stack should be reset
145
if (e.NavigationMode == NavigationMode.Reset)
146
RootFrame.Navigated += ClearBackStackAfterReset;
149
private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
151
// Unregister the event so it doesn't get called again
152
RootFrame.Navigated -= ClearBackStackAfterReset;
154
// Only clear the stack for 'new' (forward) and 'refresh' navigations
155
if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
158
// For UI consistency, clear the entire page stack
159
while (RootFrame.RemoveBackEntry() != null)
167
// Initialize the app's font and flow direction as defined in its localized resource strings.
169
// To ensure that the font of your application is aligned with its supported languages and that the
170
// FlowDirection for each of those languages follows its traditional direction, ResourceLanguage
171
// and ResourceFlowDirection should be initialized in each resx file to match these values with that
172
// file's culture. For example:
174
// AppResources.es-ES.resx
175
// ResourceLanguage's value should be "es-ES"
176
// ResourceFlowDirection's value should be "LeftToRight"
178
// AppResources.ar-SA.resx
179
// ResourceLanguage's value should be "ar-SA"
180
// ResourceFlowDirection's value should be "RightToLeft"
182
// For more info on localizing Windows Phone apps see http://go.microsoft.com/fwlink/?LinkId=262072.
184
private void InitializeLanguage()
188
// Set the font to match the display language defined by the
189
// ResourceLanguage resource string for each supported language.
191
// Fall back to the font of the neutral language if the Display
192
// language of the phone is not supported.
194
// If a compiler error is hit then ResourceLanguage is missing from
195
// the resource file.
196
RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
198
// Set the FlowDirection of all elements under the root frame based
199
// on the ResourceFlowDirection resource string for each
200
// supported language.
202
// If a compiler error is hit then ResourceFlowDirection is missing from
203
// the resource file.
204
FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection);
205
RootFrame.FlowDirection = flow;
209
// If an exception is caught here it is most likely due to either
210
// ResourceLangauge not being correctly set to a supported language
211
// code or ResourceFlowDirection is set to a value other than LeftToRight
214
if (Debugger.IsAttached)
b'\\ No newline at end of file'