-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
743 lines (641 loc) · 31.1 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.InteropServices;
using Windows.Foundation;
using Windows.Foundation.Collections;
using System.Text;
using Windows.Networking.Sockets;
using System.Collections.ObjectModel;
using Microsoft.UI.Composition.SystemBackdrops;
using Windows.UI.Popups;
using System.Threading;
using Windows.Devices.Enumeration;
using Windows.Devices.SerialCommunication;
using Windows.Storage.Streams;
using System.Threading.Tasks;
using System.IO.Ports;
using Microsoft.UI; // Needed for WindowId.
using Microsoft.UI.Windowing; // Needed for AppWindow.
using WinRT;
using WinRT.Interop;
using Windows.UI; // Needed for XAML/HWND interop.
using Windows.ApplicationModel.Core;
using Windows.UI.ViewManagement;
using Windows.ApplicationModel;
using Windows.Graphics;
using System.Diagnostics;
using System.IO;
using Tommy;
using System.Reflection.PortableExecutable;
using Windows.ApplicationModel.Activation;
using System.Xml.Linq;
using Microsoft.UI.Xaml.Media.Animation;
using FSGaryityTool_Win11.Core.Settings;
using FSGaryityTool_Win11.Views.Pages.KsyboardPage;
using FSGaryityTool_Win11.Views.Pages.MousePage;
using FSGaryityTool_Win11.Views.Pages.FanControlPage;
using FSGaryityTool_Win11.Views.Pages.FlashDownloadPage;
using FSGaryityTool_Win11.Views.Pages.FairingStudioPage;
using FSGaryityTool_Win11.Views.Pages.SerialPortPage;
using Windows.System;
using FSGaryityTool_Win11.Views.Pages.CameraControlPage;
using Microsoft.UI.Xaml.Hosting;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace FSGaryityTool_Win11
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public static string FSSoftVersion = "0.3.6";
public static string FSSoftName = "FSGravityTool Dev";
public static int FsPage = 0;
public static int defWindowBackGround = 0;
public static bool defaultNavigationViewPaneOpen;
public static MainWindow mainWindow;
//public static Page1 page1Instance;
private Dictionary<string, Type> pageTypeMap = new Dictionary<string, Type>
{
{"MainPage1", typeof(MainPage1)},
{"Page2", typeof(Page2)},
{"Page3", typeof(Page3)},
{"Page4", typeof(Page4)},
{"Page5", typeof(Page5)},
{"CameraControlMainPage", typeof(CameraControlMainPage)},
{"FSPage", typeof(FSPage)},
};
private Dictionary<int, Action> backRequestedMap = new Dictionary<int, Action>
{
{0, () => Debug.WriteLine("SerialPortPage")},
{1, () => Debug.WriteLine("FlashDownloadPage")},
{2, () => Debug.WriteLine("KeyboardPage")},
{3, () => Debug.WriteLine("MousePage")},
{4, () => Debug.WriteLine("FanControlPage")},
{5, () => Debug.WriteLine("CameraControlPage")},
{6, () => { if (FSPage.fSPage.MyWebView2.CanGoBack) FSPage.fSPage.MyWebView2.GoBack(); }},
{7, () => Debug.WriteLine("SettingsPage")},
};
void CanvasControl_Draw(
Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender,
Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
{
args.DrawingSession.DrawEllipse(155, 115, 80, 30, Microsoft.UI.Colors.Black, 3);
args.DrawingSession.DrawText("Hello, Win2D World!", 100, 100, Microsoft.UI.Colors.Yellow);
}
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
var selectedItem = (NavigationViewItem)args.SelectedItem;
string tag = (string)selectedItem.Tag;
if (pageTypeMap.ContainsKey(tag))
{
FSnvf.Navigate(pageTypeMap[tag]);
FsPage = Array.IndexOf(pageTypeMap.Keys.ToArray(), tag);
if (tag == "MainPage1")
{
UpdateSplitViewDisplayMode();
}
}
if (args.IsSettingsSelected)
{
FSnvf.Navigate(typeof(MainSettingsPage), null, new SuppressNavigationTransitionInfo());
FsPage = 7;
}
}
private AppWindow m_AppWindow;
public NavigationFailedEventHandler OnNavigationFailed { get; private set; }
public static MainWindow Instance { get; private set; }
public new static Microsoft.UI.Windowing.AppWindow AppWindow { get; set; }
///*
// 窗口的最小宽度和高度
private const int MinWidth = 642;
private const int MinHeight = 409;
// 窗口的默认宽度和高度
private const int DefaultWidth = 1840;
private const int DefaultHeight = 960;
/*
public static bool Resize(Window window, int width, int height)
{
try
{
IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
AppWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
AppWindow.Resize(new Windows.Graphics.SizeInt32 { Width = width, Height = height });
AppWindow.Changed += AppWindow_Changed;
return true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
return false;
}
private static void AppWindow_Changed(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowChangedEventArgs args)
{
try
{
if (AppWindow == null)
return;
if (AppWindow.Size.Height < MinHeight && AppWindow.Size.Width < MinWidth)
AppWindow.Resize(new Windows.Graphics.SizeInt32 { Width = MinWidth, Height = MinHeight });
else if (AppWindow.Size.Height < MinHeight)
AppWindow.Resize(new Windows.Graphics.SizeInt32 { Width = AppWindow.Size.Width, Height = MinHeight });
else if (AppWindow.Size.Width < MinWidth)
AppWindow.Resize(new Windows.Graphics.SizeInt32 { Width = MinWidth, Height = AppWindow.Size.Height });
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
//*/
public void DelayedInitialize(UIElement mainContent)
{
Task.Run(() =>
{
Thread.Sleep(500); // 延时改为0.5秒
// 创建淡出动画
///*
DispatcherQueue.TryEnqueue(() =>
{
Storyboard storyboard = new Storyboard();
DoubleAnimation fadeOutAnimation = new DoubleAnimation()
{
From = 1.0,
To = 0.0,
Duration = new Duration(TimeSpan.FromMilliseconds(50))
};
Storyboard.SetTarget(fadeOutAnimation, (ExtendedSplash)App.m_window.Content);
Storyboard.SetTargetProperty(fadeOutAnimation, "Opacity");
storyboard.Children.Add(fadeOutAnimation);
// 播放淡出动画
//storyboard.Begin();
});
//*/
Thread.Sleep(1); // 等待淡出动画完成
// 移除 ExtendedSplash
DispatcherQueue.TryEnqueue(() =>
{
((App)Application.Current).RemoveExtendedSplash(mainContent);
});
});
}
public MainWindow()
{
this.InitializeComponent();
Instance = this;
((FrameworkElement)this.Content).ActualThemeChanged += Window_ThemeChanged;
bool isFirstActivation = true;
UIElement mainContent = this.Content;
///*
//Resize(this, DefaultWidth, DefaultHeight);
//*/
// 将窗口的标题栏设置为自定义标题栏
this.ExtendsContentIntoTitleBar = true; // enable custom titlebar
SetTitleBar(AppTitleBara);
m_AppWindow = GetAppWindowForCurrentWindow();
m_AppWindow.Title = FSSoftName;//Set AppWindow
m_AppWindow.SetIcon("FSFSoftH.ico");
// 在窗口激活后注册 SizeChanged 事件处理器
this.Activated += (sender, e) =>
{
if (isFirstActivation)
{
ExtendedSplash extendedSplash = new ExtendedSplash(this);
this.Content = extendedSplash;
if (Window.Current != null)
{
Window.Current.SizeChanged += extendedSplash.ExtendedSplash_OnResize;
}
}
};
//page1Instance = new Page1(); // 初始化Page1实例
Task.Run(() =>
{
SettingsCoreServices.CheckSettingFolder();
SettingsCoreServices.AddTomlFile();
SettingsCoreServices.CheckSettingsFileVersion();
// 在初始化完成后,回到 UI 线程移除 ExtendedSplash
this.DispatcherQueue.TryEnqueue(() =>
{
LaunageSetting();
using (StreamReader reader = File.OpenText(SettingsCoreServices.FSGravityToolsSettingsToml))
{
TomlTable settingstomlr = TOML.Parse(reader);
string Value = settingstomlr["FSGravitySettings"]["DefaultNavigationViewPaneOpen"];
defaultNavigationViewPaneOpen = System.Convert.ToBoolean(Value);
FSnv.IsPaneOpen = defaultNavigationViewPaneOpen;
Debug.WriteLine("Pane" + defaultNavigationViewPaneOpen);
}
//设置默认页面
using (StreamReader reader = File.OpenText(SettingsCoreServices.FSGravityToolsSettingsToml))
{
TomlTable settingstomlr = TOML.Parse(reader);
Debug.WriteLine("Print:" + settingstomlr["FSGravitySettings"]["DefaultNvPage"]);
int NvPage = int.Parse(settingstomlr["FSGravitySettings"]["DefaultNvPage"]);
FSnv.SelectedItem = FSnv.MenuItems[NvPage]; //设置默认页面
FsPage = NvPage;
}
using (StreamReader reader = File.OpenText(SettingsCoreServices.FSGravityToolsSettingsToml))
{
TomlTable settingstomlr = TOML.Parse(reader);
Debug.WriteLine("Print:" + settingstomlr["FSGravitySettings"]["SoftBackground"]);
int defPageBackground = int.Parse(settingstomlr["FSGravitySettings"]["SoftBackground"]);
defWindowBackGround = defPageBackground;
lastdefWindowBackGround = defPageBackground;
}
TitleBarTextBlock.Text = FSSoftName;
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
{
// 连接策略对象。
m_configurationSource = new Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration();
this.Activated += Window_Activated; // 当窗口被激活时的事件处理。
this.Closed += Window_Closed; // 当窗口被关闭时的事件处理。
// 初始配置状态。
m_configurationSource.IsInputActive = true; // 设置输入活动状态为真。
SetConfigurationSourceTheme(); // 设置配置源主题。
// 根据defWindowBackGround的值选择背景效果的类型。
switch (defWindowBackGround)
{
case 0:
m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();
m_acrylicController.Kind = Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin;
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource);
break;
case 1:
m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();
m_acrylicController.Kind = Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base;
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource);
break;
case 2:
m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController();
m_micaController.Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base;
m_micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_micaController.SetSystemBackdropConfiguration(m_configurationSource);
break;
case 3:
m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController();
m_micaController.Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt;
m_micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_micaController.SetSystemBackdropConfiguration(m_configurationSource);
break;
}
}
});
});
/*
if (AppWindowTitleBar.IsCustomizationSupported())
{
AppWindowTitleBar m_TitleBar = m_AppWindow.TitleBar;
// Set active window colors.
// Note: No effect when app is running on Windows 10
// because color customization is not supported.
m_TitleBar.ForegroundColor = Color.FromArgb(255, 255, 255, 255);
m_TitleBar.BackgroundColor = Color.FromArgb(255, 22, 22, 22);
m_TitleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255);
m_TitleBar.ButtonBackgroundColor = Color.FromArgb(255, 22, 22, 22);
m_TitleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0);
m_TitleBar.ButtonHoverBackgroundColor = Color.FromArgb(255, 230, 224, 0);
m_TitleBar.ButtonPressedForegroundColor = Color.FromArgb(255, 0, 0, 0);
m_TitleBar.ButtonPressedBackgroundColor = Color.FromArgb(255, 230, 224, 0);
// Set inactive window colors.
// Note: No effect when app is running on Windows 10
// because color customization is not supported.
m_TitleBar.InactiveForegroundColor = Colors.Gainsboro;
m_TitleBar.InactiveBackgroundColor = Color.FromArgb(255, 22, 22, 22);
m_TitleBar.ButtonInactiveForegroundColor = Colors.Gainsboro;
m_TitleBar.ButtonInactiveBackgroundColor = Color.FromArgb(255, 22, 22, 22);
}*/
this.Activated += (sender, e) =>
{
//AppWindow.Changed += AppWindow_Changed;
if (isFirstActivation)
{
DelayedInitialize(mainContent);
isFirstActivation = false;
}
LoadingEnd();
};
}
int lastdefWindowBackGround = 0;
public static bool IsFirstLoadding = true;
public void LoadingEnd()
{
if (IsFirstLoadding) Loadingprg();
}
public void Loadingprg()
{
Task.Run(() =>
{
switch (FsPage)
{
case 0: Thread.Sleep(1450);
break;
case 4: Thread.Sleep(100);
break;
}
DispatcherQueue.TryEnqueue(() =>
{
var fadeOutAnimation = new DoubleAnimation
{
To = 0,
Duration = TimeSpan.FromMilliseconds(75)
};
var storyboard = new Storyboard();
storyboard.Children.Add(fadeOutAnimation);
Storyboard.SetTarget(fadeOutAnimation, FsStartImage);
Storyboard.SetTargetProperty(fadeOutAnimation, "Opacity");
storyboard.Begin();
});
Thread.Sleep(200);
DispatcherQueue.TryEnqueue(() =>
{
FsStartImage.Visibility = Visibility.Collapsed;
IsFirstLoadding = false;
});
});
}
public void LaunageSetting()
{
SerialPortI.Content = Page1.LanguageText("serialPort");
DownFlashI.Content = Page1.LanguageText("download Flash");
KeyboardI.Content = Page1.LanguageText("keyboard");
MouseI.Content = Page1.LanguageText("mouse");
}
public void WindowBackSetting()
{
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
{
using (StreamReader reader = File.OpenText(SettingsCoreServices.FSGravityToolsSettingsToml)) // 打开TOML文件
{
TomlTable settingstomlr = TOML.Parse(reader);
Debug.WriteLine("Print:" + settingstomlr["FSGravitySettings"]["SoftBackground"]);
int defPageBackground = int.Parse(settingstomlr["FSGravitySettings"]["SoftBackground"]);
if (defPageBackground != lastdefWindowBackGround)
{
defWindowBackGround = defPageBackground;
}
lastdefWindowBackGround = defPageBackground;
}
SetConfigurationSourceTheme(); // 设置配置源主题。
// 根据defWindowBackGround的值选择背景效果的类型。
switch (defWindowBackGround)
{
case 0:
if (m_acrylicController == null)
{
m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();
}
m_acrylicController.Kind = Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin;
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource);
break;
case 1:
if (m_acrylicController == null)
{
m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();
}
m_acrylicController.Kind = Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base;
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource);
break;
case 2:
if (m_micaController == null)
{
m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController();
}
m_micaController.Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base;
m_micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_micaController.SetSystemBackdropConfiguration(m_configurationSource);
break;
case 3:
if (m_micaController == null)
{
m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController();
}
m_micaController.Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt;
m_micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_micaController.SetSystemBackdropConfiguration(m_configurationSource);
break;
}
// 释放当前背景效果的资源
ReleaseCurrentBackdropResources();
}
}
private void ReleaseCurrentBackdropResources()
{
Task.Run(() =>
{
// 释放m_acrylicController的资源,并将其设置为null
if (m_acrylicController != null)
{
if (defWindowBackGround == 2 || defWindowBackGround == 3)
{
//Thread.Sleep(100);
m_acrylicController.Dispose();
m_acrylicController = null;
}
}
// 释放m_micaController的资源,并将其设置为null
if (m_micaController != null)
{
if (defWindowBackGround == 0 || defWindowBackGround == 1)
{
//Thread.Sleep(100);
m_micaController.Dispose();
m_micaController = null;
}
}
});
}
// 定义一个DesktopAcrylicController对象,用于控制窗口的背景
Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController m_acrylicController;
// 定义一个MicaController对象,用于控制云母效果
Microsoft.UI.Composition.SystemBackdrops.MicaController m_micaController;
// 定义一个SystemBackdropConfiguration对象,用于配置窗口的背景
Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration m_configurationSource;
// 当窗口被激活时,此方法会被调用
private void Window_Activated(object sender, WindowActivatedEventArgs args)
{
// 根据窗口的激活状态来更新m_configurationSource.IsInputActive的值
m_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
// 根据窗口的激活状态来设置背景效果
if (m_configurationSource.IsInputActive)
{
// 使用云母效果
if (defWindowBackGround == 2 || defWindowBackGround == 3)
{
if (m_micaController == null)
{
m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController();
}
m_micaController.Kind = (defWindowBackGround == 2) ? Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base : Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt;
m_micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_micaController.SetSystemBackdropConfiguration(m_configurationSource);
}
// 使用亚克力效果
if (defWindowBackGround == 0 || defWindowBackGround == 1)
{
if (m_acrylicController == null)
{
m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController();
}
m_acrylicController.Kind = (defWindowBackGround == 0) ? Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin : Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base;
m_acrylicController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource);
}
}
}
// 当窗口被关闭时,此方法会被调用
private void Window_Closed(object sender, WindowEventArgs args)
{
// 释放m_acrylicController的资源,并将其设置为null
if (m_acrylicController != null)
{
m_acrylicController.Dispose();
m_acrylicController = null;
}
// 释放m_micaController的资源,并将其设置为null
if (m_micaController != null)
{
m_micaController.Dispose();
m_micaController = null;
}
// 移除窗口激活事件的处理方法
this.Activated -= Window_Activated;
// 将配置对象设置为null
m_configurationSource = null;
}
// 当窗口的主题改变时,此方法会被调用
private void Window_ThemeChanged(FrameworkElement sender, object args)
{
Debug.WriteLine("Change");
// 如果配置对象不为null,则根据当前的主题来更新m_configurationSource.Theme的值
if (m_configurationSource != null)
{
SetConfigurationSourceTheme();
WindowBackSetting();
}
}
// 根据当前的主题来设置m_configurationSource.Theme的值
private void SetConfigurationSourceTheme()
{
var theme = ((FrameworkElement)this.Content).ActualTheme;
switch (theme)
{
case ElementTheme.Dark:
// 如果主题是深色,SystemBackdropTheme会被设置为Dark
m_configurationSource.Theme = Microsoft.UI.Composition.SystemBackdrops.SystemBackdropTheme.Dark;
break;
case ElementTheme.Light:
// 如果主题是浅色,SystemBackdropTheme会被设置为Light
m_configurationSource.Theme = Microsoft.UI.Composition.SystemBackdrops.SystemBackdropTheme.Light;
break;
case ElementTheme.Default:
// 如果主题是默认的,SystemBackdropTheme会被设置为Default
m_configurationSource.Theme = Microsoft.UI.Composition.SystemBackdrops.SystemBackdropTheme.Default;
break;
}
var titleBar = m_AppWindow.TitleBar;
if (theme == ElementTheme.Dark)
{
titleBar.ButtonForegroundColor = Colors.White;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(64, 128, 128, 128);
}
else
{
titleBar.ButtonForegroundColor = Colors.Black;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(64, 128, 128, 128);
}
}
// Call your extend acrylic code in the OnLaunched event, after
// calling Window.Current.Activate.
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WindowNative.GetWindowHandle(this);
Microsoft.UI.WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
private void NavigationView_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
{
if (backRequestedMap.ContainsKey(FsPage))
{
backRequestedMap[FsPage]();
}
}
private void NavigationView_DisplayModeChanged(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewDisplayModeChangedEventArgs args)
{
if (args.DisplayMode == Microsoft.UI.Xaml.Controls.NavigationViewDisplayMode.Minimal)
{
AppTitleBara.Margin = new Thickness(48, 0, 0, 0);
}
else
{
AppTitleBara.Margin = new Thickness(0, 0, 0, 0);
}
UpdateSplitViewDisplayMode();
}
private void UpdateSplitViewDisplayMode()
{
var currentPage = this.FSnvf.Content as MainPage1;
if (currentPage != null)
{
if (this.FSnv.DisplayMode == NavigationViewDisplayMode.Expanded)
{
currentPage.ChangeSplitViewDisplayMode(SplitViewDisplayMode.CompactInline);
}
else
{
currentPage.ChangeSplitViewDisplayMode(SplitViewDisplayMode.CompactOverlay);
}
}
}
private void FSnv_PaneOpened(NavigationView sender, object args)
{
Debug.WriteLine(defaultNavigationViewPaneOpen);
SettingsCoreServices.SaveSetting("FSGravitySettings", "DefaultNavigationViewPaneOpen", "true");
}
private void FSnv_PaneClosed(NavigationView sender, object args)
{
Debug.WriteLine(defaultNavigationViewPaneOpen);
SettingsCoreServices.SaveSetting("FSGravitySettings", "DefaultNavigationViewPaneOpen", "false");
}
/*
public class Tab1
{
private SerialPort serialPort1;
public Tab1()
{
this.serialPort1 = new SerialPort();
// 配置并打开serialPort1
}
// 使用serialPort1进行通信
}
public class Tab2
{
private SerialPort serialPort2;
public Tab2()
{
this.serialPort2 = new SerialPort();
// 配置并打开serialPort2
}
// 使用serialPort2进行通信
}
*/
}
}