Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

App.xaml.cs 4.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  1. // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
  2. namespace WorkingWithWebview.WinPhone81
  3. {
  4. using System;
  5. using Windows.ApplicationModel;
  6. using Windows.ApplicationModel.Activation;
  7. using Windows.UI.Xaml;
  8. using Windows.UI.Xaml.Controls;
  9. using Windows.UI.Xaml.Media.Animation;
  10. using Windows.UI.Xaml.Navigation;
  11. /// <summary>
  12. /// Provides application-specific behavior to supplement the default Application class.
  13. /// </summary>
  14. public sealed partial class App : Application
  15. {
  16. private TransitionCollection transitions;
  17. /// <summary>
  18. /// Initializes the singleton application object. This is the first line of authored code
  19. /// executed, and as such is the logical equivalent of main() or WinMain().
  20. /// </summary>
  21. public App()
  22. {
  23. this.InitializeComponent();
  24. this.Suspending += this.OnSuspending;
  25. }
  26. /// <summary>
  27. /// Invoked when the application is launched normally by the end user. Other entry points
  28. /// will be used when the application is launched to open a specific file, to display
  29. /// search results, and so forth.
  30. /// </summary>
  31. /// <param name="e">Details about the launch request and process.</param>
  32. protected override void OnLaunched(LaunchActivatedEventArgs e)
  33. {
  34. #if DEBUG
  35. if (System.Diagnostics.Debugger.IsAttached)
  36. {
  37. this.DebugSettings.EnableFrameRateCounter = true;
  38. }
  39. #endif
  40. Frame rootFrame = Window.Current.Content as Frame;
  41. // Do not repeat app initialization when the Window already has content,
  42. // just ensure that the window is active
  43. if (rootFrame == null)
  44. {
  45. // Create a Frame to act as the navigation context and navigate to the first page
  46. rootFrame = new Frame();
  47. // TODO: change this value to a cache size that is appropriate for your application
  48. rootFrame.CacheSize = 1;
  49. // Set the default language
  50. rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
  51. Xamarin.Forms.Forms.Init(e);
  52. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  53. {
  54. // TODO: Load state from previously suspended application
  55. }
  56. // Place the frame in the current Window
  57. Window.Current.Content = rootFrame;
  58. }
  59. if (rootFrame.Content == null)
  60. {
  61. // Removes the turnstile navigation for startup.
  62. if (rootFrame.ContentTransitions != null)
  63. {
  64. this.transitions = new TransitionCollection();
  65. foreach (var c in rootFrame.ContentTransitions)
  66. {
  67. this.transitions.Add(c);
  68. }
  69. }
  70. rootFrame.ContentTransitions = null;
  71. rootFrame.Navigated += this.RootFrame_FirstNavigated;
  72. // When the navigation stack isn't restored navigate to the first page,
  73. // configuring the new page by passing required information as a navigation
  74. // parameter
  75. if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
  76. {
  77. throw new Exception("Failed to create initial page");
  78. }
  79. }
  80. // Ensure the current window is active
  81. Window.Current.Activate();
  82. }
  83. /// <summary>
  84. /// Restores the content transitions after the app has launched.
  85. /// </summary>
  86. /// <param name="sender">The object where the handler is attached.</param>
  87. /// <param name="e">Details about the navigation event.</param>
  88. private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
  89. {
  90. var rootFrame = sender as Frame;
  91. rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
  92. rootFrame.Navigated -= this.RootFrame_FirstNavigated;
  93. }
  94. /// <summary>
  95. /// Invoked when application execution is being suspended. Application state is saved
  96. /// without knowing whether the application will be terminated or resumed with the contents
  97. /// of memory still intact.
  98. /// </summary>
  99. /// <param name="sender">The source of the suspend request.</param>
  100. /// <param name="e">Details about the suspend request.</param>
  101. private void OnSuspending(object sender, SuspendingEventArgs e)
  102. {
  103. var deferral = e.SuspendingOperation.GetDeferral();
  104. // TODO: Save application state and stop any background activity
  105. deferral.Complete();
  106. }
  107. }
  108. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...