-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
106 lines (97 loc) · 4.24 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
106 lines (97 loc) · 4.24 KB
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
using System;
using System.IO;
using System.Runtime.InteropServices;
using FastTransfer.Services;
using FastTransfer.Views;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace FastTransfer;
public sealed partial class MainWindow : Window
{
private const int WM_SETICON = 0x0080;
private const int ICON_BIG = 1;
private const int ICON_SMALL = 0;
private const uint IMAGE_ICON = 1;
private const uint LR_LOADFROMFILE = 0x00000010;
private const uint LR_DEFAULTSIZE = 0x00000040;
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint type, int cx, int cy, uint fuLoad);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public MainWindow()
{
InitializeComponent();
SystemBackdrop = new Microsoft.UI.Xaml.Media.MicaBackdrop();
RootGrid.RequestedTheme = App.MapTheme(AppSettings.Current);
try
{
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new Windows.Graphics.SizeInt32(1280, 820));
ApplyAppIcon(hwnd);
}
catch (Exception ex) { AppLog.Warn("MainWindow", ex.Message); }
// 首页
ContentFrame.Navigate(typeof(HomePage));
}
/// <summary>把 FastTransfer 图标应用于标题栏 / 任务栏窗口图标(自包含部署从输出目录加载;失败静默)。</summary>
private static void ApplyAppIcon(IntPtr hwnd)
{
try
{
var iconPath = Path.Combine(AppContext.BaseDirectory, "Assets", "App.ico");
if (!File.Exists(iconPath)) return;
IntPtr hIcon = LoadImage(IntPtr.Zero, iconPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
if (hIcon == IntPtr.Zero) return;
SendMessage(hwnd, WM_SETICON, (IntPtr)ICON_BIG, hIcon);
SendMessage(hwnd, WM_SETICON, (IntPtr)ICON_SMALL, hIcon);
}
catch (Exception ex) { AppLog.Warn("MainWindow", $"设置窗口图标失败: {ex.Message}"); }
}
/// <summary>供各页调用切换到指定导航标签页(§2.3 全面打通:文件管理→工作流等)。</summary>
public void NavTo(string tag)
{
Type page = tag.ToLowerInvariant() switch
{
"home" => typeof(HomePage),
"transfer" => typeof(TransferPage),
"filemanager" => typeof(FileManagerPage),
"globalsearch" => typeof(GlobalSearchPage),
"rename" => typeof(RenameToolPage),
"workflow" => typeof(WorkflowPage),
"devices" => typeof(DevicesPage),
"settings" => typeof(SettingsPage),
"logs" => typeof(LogsPage),
_ => typeof(HomePage)
};
if (ContentFrame.CurrentSourcePageType != page)
ContentFrame.Navigate(page, null, infoOverride: new Microsoft.UI.Xaml.Media.Animation.EntranceNavigationTransitionInfo());
}
private void OnNavSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.SelectedItemContainer?.Tag is not string tag) return;
try
{
Type page = tag switch
{
"home" => typeof(HomePage),
"transfer" => typeof(TransferPage),
"filemanager" => typeof(FileManagerPage),
"globalsearch" => typeof(GlobalSearchPage),
"rename" => typeof(RenameToolPage),
"workflow" => typeof(WorkflowPage),
"devices" => typeof(DevicesPage),
"settings" => typeof(SettingsPage),
"logs" => typeof(LogsPage),
_ => typeof(HomePage)
};
if (ContentFrame.CurrentSourcePageType != page)
ContentFrame.Navigate(page, null, infoOverride: new Microsoft.UI.Xaml.Media.Animation.EntranceNavigationTransitionInfo());
}
catch (Exception ex)
{
AppLog.Error("MainWindow", ex, $"导航到 {tag} 失败");
}
}
}