
今天百度了“WPF最小化托盘”,并没有找到合适的和自己想要的案例,后来谷歌到了一个简短且能实现的代码,在这做个记录。
谷歌搜索后参考的文章
效果演示:

主要代码如下:
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
|
/// <summary> /// Window1.xaml 的交互逻辑 /// </summary> public partial class Window1 : Window { public Window1() { InitializeComponent(); System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Icon = new System.Drawing.Icon(@".imageslupita.ico"); ni.Visible = true; ni.DoubleClick += delegate (object sender, EventArgs args) { this.Show(); this.WindowState = WindowState.Normal; }; } protected override void OnStateChanged(EventArgs e) { if (WindowState == System.Windows.WindowState.Minimized) this.Hide(); base.OnStateChanged(e); } }
|
近期评论