新增托盘图标

This commit is contained in:
2026-03-01 10:42:42 +08:00
parent 0ba966cef2
commit e03e1b9766
26 changed files with 582 additions and 72 deletions

View File

@@ -1,11 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -82,6 +80,7 @@ public partial class MainWindow
#region
public ICommand ShowSelectedItemsCommand { get; set; }
public ICommand ToggleDetailsCommand { get; set; }
public ICommand ShowWindowCommand { get; set; }
[RelayCommand]
private void AddArea()
@@ -227,6 +226,7 @@ public partial class MainWindow
{
ShowSelectedItemsCommand = new RelayCommand(ShowSelectedItems);
ToggleDetailsCommand = new RelayCommand<PersonItem>(ToggleDetails);
ShowWindowCommand = new RelayCommand(ShowWindow);
}
#endregion
@@ -456,12 +456,38 @@ public partial class MainWindow
case 2:
MyTutorial.ShowStep(StartBtn, "删除功能", "谨慎使用,这会清除数据。", "2 / 2");
break;
default:
MyTutorial.Close();
break;
}
}
private void ShowWindow()
{
this.Show();
this.WindowState = WindowState.Normal;
this.Activate(); // 激活窗口使其置顶
}
// --- 2. 右键菜单的 Click 事件 (Code-behind 风格) ---
private void MenuShow_Click(object sender, RoutedEventArgs e)
{
ShowWindow();
}
private void MenuExit_Click(object sender, RoutedEventArgs e)
{
// 真正退出程序
Application.Current.Shutdown();
}
// --- 3. 重写关闭事件实现“点X最小化到托盘” ---
protected override void OnClosing(CancelEventArgs e)
{
// 阻止窗口真正销毁
e.Cancel = true;
// 隐藏窗口(此时托盘图标依然在运行)
this.Hide();
}
}
#region