-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
149 lines (130 loc) · 5.21 KB
/
App.xaml.cs
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using Microsoft.UI.Xaml;
using WorkdayCalculator.Views;
using WorkdayCalculator.Helpers;
using Microsoft.UI.Xaml.Controls;
using WorkdayCalculator.Common;
using System;
using Windows.ApplicationModel.Activation;
using Microsoft.UI.Xaml.Navigation;
using Windows.Graphics;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace WorkdayCalculator;
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}
private static Window? MainWindow;
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
{
MainWindow = WindowHelper.CreateWindow();
MainWindow.ExtendsContentIntoTitleBar = true;
SizeInt32 size = new SizeInt32(500, 500);
MainWindow.AppWindow.Resize(size);
EnsureWindow();
}
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
private async void EnsureWindow(IActivatedEventArgs? args = null)
{
Frame rootFrame = GetRootFrame();
Type targetPageType = typeof(HomePage);
string targetPageArguments = string.Empty;
if (args != null)
{
if (args.Kind == ActivationKind.Launch)
{
targetPageArguments = ((Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)args).Arguments;
}
}
var eventargs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
if (eventargs != null && eventargs.Kind is Microsoft.Windows.AppLifecycle.ExtendedActivationKind.Protocol && eventargs.Data is ProtocolActivatedEventArgs)
{
ProtocolActivatedEventArgs ProtocolArgs = (ProtocolActivatedEventArgs)eventargs.Data;
var uri = ProtocolArgs.Uri.LocalPath.Replace("/", "");
targetPageArguments = uri;
//string targetId = string.Empty;
//if (uri == "AllControls")
//{
// {
// targetPageType = typeof(AllControlsPage);
// }
// else if (uri == "NewControls")
// {
// targetPageType = typeof(HomePage);
// }
// else if (ControlInfoDataSource.Instance.Groups.Any(g => g.UniqueId == uri))
// {
// targetPageType = typeof(SectionPage);
// }
// else if (ControlInfoDataSource.Instance.Groups.Any(g => g.Items.Any(i => i.UniqueId == uri)))
// {
// targetPageType = typeof(ItemPage);
// }
//}
}
NavigationViewPage rootPage = (NavigationViewPage)MainWindow!.Content as NavigationViewPage;
rootPage.Navigate(targetPageType, targetPageArguments);
if (targetPageType == typeof(HomePage))
{
((Microsoft.UI.Xaml.Controls.NavigationViewItem)((NavigationViewPage)App.MainWindow.Content).NavigationView.MenuItems[0]).IsSelected = true;
}
MainWindow.Activate();
}
private Frame GetRootFrame()
{
Frame rootFrame;
NavigationViewPage? rootPage = MainWindow!.Content as NavigationViewPage;
if (rootPage == null)
{
rootPage = new NavigationViewPage();
rootFrame = (Frame)rootPage.FindName("rootFrame");
if (rootFrame == null)
{
throw new Exception("Root frame not found");
}
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
rootFrame.NavigationFailed += OnNavigationFailed;
MainWindow.Content = rootPage;
}
else
{
rootFrame = (Frame)rootPage.FindName("rootFrame");
}
return rootFrame;
}
}
///// Code copy-pasted from the WinUI 3 Windowing sample
///// <summary>
///// Creates a new Window instance for the application.
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void createNewWindow_Click(object sender, RoutedEventArgs e)
//{
// // C# code to create a new window
// var newWindow = WindowHelper.CreateWindow();
// var rootPage = new NavigationRootPage();
// rootPage.RequestedTheme = ThemeHelper.RootTheme;
// newWindow.Content = rootPage;
// newWindow.Activate();
// // C# code to navigate in the new window
// var targetPageType = typeof(HomePage);
// string targetPageArguments = string.Empty;
// rootPage.Navigate(targetPageType, targetPageArguments);
//}