Пример #1
0
        /// <summary>
        /// 显示托盘图标
        /// </summary>
        public void ShowNotifyIcon()
        {
            if (PART_TaskbarIcon != null)
            {
                return;
            }
            PART_TaskbarIcon             = new TaskbarIcon();
            PART_TaskbarIcon.ToolTipText = "SimpleRemote";                                                             //最小化到托盘时,鼠标点击时显示的文本
            PART_TaskbarIcon.Icon        = new System.Drawing.Icon(CommonServices.GetResourceStream("Icon/Logo.ico")); //程序图标
            //构建菜单
            ContextMenu menu = new ContextMenu();

            menu.MinWidth = 100;
            MenuItem menuItem = new MenuItem {
                Header = "退出"
            };

            menuItem.Click += (s, e) =>
            {
                PART_TaskbarIcon = null;
                Application.Current.Shutdown(0);
            };
            menu.Items.Add(menuItem);
            PART_TaskbarIcon.ContextMenu = menu;

            PART_TaskbarIcon.TrayLeftMouseDown += (s, e) =>
            {
                if (IsVisible)
                {
                    Visibility = Visibility.Hidden;
                }
                else
                {
                    Visibility = Visibility.Visible;
                    Activate();
                }
            };
        }