Skip to content

Commit ce466a3

Browse files
committed
testapp: Add C# UWP app
1 parent a12b2fd commit ce466a3

18 files changed

+426
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/project.lock.json
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application
2+
x:Class="UWP.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:UWP"
6+
RequestedTheme="Light">
7+
8+
</Application>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel;
7+
using Windows.ApplicationModel.Activation;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
namespace UWP
19+
{
20+
/// <summary>
21+
/// Provides application-specific behavior to supplement the default Application class.
22+
/// </summary>
23+
sealed partial class App : Application
24+
{
25+
/// <summary>
26+
/// Initializes the singleton application object. This is the first line of authored code
27+
/// executed, and as such is the logical equivalent of main() or WinMain().
28+
/// </summary>
29+
public App()
30+
{
31+
this.InitializeComponent();
32+
this.Suspending += OnSuspending;
33+
}
34+
35+
/// <summary>
36+
/// Invoked when the application is launched normally by the end user. Other entry points
37+
/// will be used such as when the application is launched to open a specific file.
38+
/// </summary>
39+
/// <param name="e">Details about the launch request and process.</param>
40+
protected override void OnLaunched(LaunchActivatedEventArgs e)
41+
{
42+
43+
#if DEBUG
44+
if (System.Diagnostics.Debugger.IsAttached)
45+
{
46+
this.DebugSettings.EnableFrameRateCounter = true;
47+
}
48+
#endif
49+
50+
Frame rootFrame = Window.Current.Content as Frame;
51+
52+
// Do not repeat app initialization when the Window already has content,
53+
// just ensure that the window is active
54+
if (rootFrame == null)
55+
{
56+
// Create a Frame to act as the navigation context and navigate to the first page
57+
rootFrame = new Frame();
58+
59+
rootFrame.NavigationFailed += OnNavigationFailed;
60+
61+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
62+
{
63+
//TODO: Load state from previously suspended application
64+
}
65+
66+
// Place the frame in the current Window
67+
Window.Current.Content = rootFrame;
68+
}
69+
70+
if (rootFrame.Content == null)
71+
{
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+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
76+
}
77+
// Ensure the current window is active
78+
Window.Current.Activate();
79+
}
80+
81+
/// <summary>
82+
/// Invoked when Navigation to a certain page fails
83+
/// </summary>
84+
/// <param name="sender">The Frame which failed navigation</param>
85+
/// <param name="e">Details about the navigation failure</param>
86+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
87+
{
88+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
89+
}
90+
91+
/// <summary>
92+
/// Invoked when application execution is being suspended. Application state is saved
93+
/// without knowing whether the application will be terminated or resumed with the contents
94+
/// of memory still intact.
95+
/// </summary>
96+
/// <param name="sender">The source of the suspend request.</param>
97+
/// <param name="e">Details about the suspend request.</param>
98+
private void OnSuspending(object sender, SuspendingEventArgs e)
99+
{
100+
var deferral = e.SuspendingOperation.GetDeferral();
101+
//TODO: Save application state and stop any background activity
102+
deferral.Complete();
103+
}
104+
}
105+
}
1.4 KB
Loading
7.52 KB
Loading
2.87 KB
Loading
1.61 KB
Loading
1.23 KB
Loading
1.42 KB
Loading
3.13 KB
Loading

0 commit comments

Comments
 (0)