WPF NotifyIcon
关于NotifyIcon
1、创建全局对象
2、未登录时图标
3、正在登录图标
4、登录成功图标
5、收到消息心态图标
6、图标右键菜单
7、单击/双击图标事件
1、创建全局对象
public class Globle { public static void Init() { NotifyIconInit(); } public static System.Windows.Forms.NotifyIcon NI = new System.Windows.Forms.NotifyIcon(); }
2、未登录时图标
Globle.NI.Icon = new System.Drawing.Icon(SrcPath + @"/favicon.ico", new System.Drawing.Size(16, 16));
图标闪烁
private static Icon blank = new Icon(Common.Utils.GetPath("/blank.ico"), new System.Drawing.Size(16, 16)); private static Icon flicker = new Icon(Common.Utils.GetPath("/favicon.ico"), new System.Drawing.Size(16, 16)); private static bool blink = false; private static DispatcherTimer timer = new DispatcherTimer(); /// <summary> /// 开始闪烁 /// </summary> /// <param name="icon">自定义图标</param> public static void NotifyIconFlicker(Icon icon = null) { if (icon != null) flicker = icon; timer.Interval = new TimeSpan(0, 0, 0, 0, 300); timer.Tick += timer_Tick; timer.IsEnabled = true; timer.Start(); } /// <summary> /// 结束闪烁 /// </summary> public static void NotifyIconFlickerStop() { timer.Stop(); Dispatcher.CurrentDispatcher.Invoke(new Action(() => { Globle.NI.Icon = flicker; })); } private static void timer_Tick(object sender, EventArgs e) { if (!blink) { Dispatcher.CurrentDispatcher.Invoke(new Action(() => { Globle.NI.Icon = flicker; })); } else { Dispatcher.CurrentDispatcher.Invoke(new Action(() => { Globle.NI.Icon = blank; })); } blink = !blink; }