This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
141 lines (126 loc) · 4.95 KB
/
MainWindow.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
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
using System;
using System.Reflection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Navigation;
using Windows_Cleanup_WinUI_3.Views;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace Windows_Cleanup_WinUI_3;
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
private NavigationViewItem _lastItem;
public MainWindow()
{
//var exists = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1;
//if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) System.Diagnostics.Process.GetCurrentProcess().Kill();
InitializeComponent();
Activated += MainWindow_Activated;
ExtendsContentIntoTitleBar = true;
SetTitleBar(AppTitleBar);
}
private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
{
AppTitleBar.Margin = new Thickness()
{
Left = sender.CompactPaneLength * (sender.DisplayMode == NavigationViewDisplayMode.Minimal ? 2 : 1),
Top = AppTitleBar.Margin.Top,
Right = AppTitleBar.Margin.Right,
Bottom = AppTitleBar.Margin.Bottom
};
}
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
{
if (args.WindowActivationState == WindowActivationState.Deactivated)
{
AppTitleTextBlock.Foreground =
(SolidColorBrush)App.Current.Resources["WindowCaptionForegroundDisabled"];
}
else
{
AppTitleTextBlock.Foreground =
(SolidColorBrush)App.Current.Resources["WindowCaptionForeground"];
}
}
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
}
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
var item = args.InvokedItemContainer as NavigationViewItem;
if (item == null || item == _lastItem)
return;
var ClickedView = item.Tag?.ToString();
//NavView.Header = $"{ClickedView}";
if (!NavigateToView(ClickedView)) return;
_lastItem = item;
}
private bool NavigateToView(string clickedView)
{
var view = Assembly.GetExecutingAssembly().GetType($"Windows_Cleanup_WinUI_3.Views.{clickedView}");
if (string.IsNullOrWhiteSpace(clickedView) || view == null)
return false;
ContentFrame.Navigate(view, null, new EntranceNavigationTransitionInfo());
return true;
}
private void NavView_Loaded(object sender, RoutedEventArgs e)
{
foreach (NavigationViewItemBase item in NavView.MenuItems)
{
if (item is NavigationViewItem && item.Tag.ToString() == "HomeView")
{
NavView.SelectedItem = item;
break;
}
}
ContentFrame.Navigate(typeof(HomeView));
}
private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
{
ContentFrame.Navigate(typeof(SettingsView));
NavView.Header = "Settings";
}
else
{
NavigationViewItem item = args.SelectedItem as NavigationViewItem;
switch (item.Tag)
{
case "HomeView":
ContentFrame.Navigate(typeof(HomeView));
NavView.Header = "Home";
break;
case "BasicToolsView":
ContentFrame.Navigate(typeof(BasicToolsView));
NavView.Header = "Basic Tools";
break;
case "NetToolsView":
ContentFrame.Navigate(typeof(NetToolsView));
NavView.Header = "Net Tools";
break;
case "PowerOptionsView":
ContentFrame.Navigate(typeof(PowerOptionsView));
NavView.Header = "Power Options";
break;
case "AdvancedToolsView":
ContentFrame.Navigate(typeof(AdvancedToolsView));
NavView.Header = "Advanced Tools";
break;
default:
break;
}
}
}
private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
{
GC.Collect();
}
}