HandyControl icon indicating copy to clipboard operation
HandyControl copied to clipboard

Bug title

Open LickBag opened this issue 1 year ago • 1 comments

Describe the bug

我通过xaml的方式增加托盘图标,但是每次通过mstsc远程连接运行这个软件的电脑后就会创建一个新的托盘图标,mstsc远程连接N次,那么托盘图标就会有N+1个,但是使用C#代码在窗口Load的时候创建托盘图标就没问题。

<hc:NotifyIcon Token="SimulatorNotifyIconToken" Text="模拟器" > <hc:NotifyIcon.ContextMenu> <ContextMenu> <MenuItem Header="开机启动,并模拟" IsCheckable="True" IsChecked="{Binding AutoBoot}" StaysOpenOnClick="True" /> <Separator BorderBrush="LightGray" BorderThickness="1" Margin="-30,0,0,0" /> <MenuItem Command="{Binding PushMainWindow2Top}" Header="显示主窗口" /> <MenuItem Command="{Binding ExitCommand}" Header="退出程序" /> </ContextMenu> </hc:NotifyIcon.ContextMenu> <hc:Interaction.Triggers> <hc:EventTrigger EventName="Click"> <hc:EventToCommand Command="{Binding PushMainWindow2Top}"/> </hc:EventTrigger> </hc:Interaction.Triggers> </hc:NotifyIcon>

`private void InitTray() { HandyControl.Controls.NotifyIcon notifyIcon = new HandyControl.Controls.NotifyIcon(); notifyIcon.Token = "SimulatorNotifyIconToken"; notifyIcon.Text = "模拟器";

var contextMenu = new ContextMenu();

var menuItem = new MenuItem();
menuItem.Header = "开机启动,并模拟";
menuItem.IsCheckable = true;
menuItem.IsChecked = this.AutoBoot;
menuItem.StaysOpenOnClick = true;
menuItem.Checked += (s, a) =>
{
    this.AutoBoot = true;
};
menuItem.Unchecked += (s, a) =>
{
    this.AutoBoot = false;
};
contextMenu.Items.Add(menuItem);

Separator separator = new Separator();
separator.BorderBrush = Brushes.LightGray;
separator.BorderThickness = new Thickness(1);
separator.Margin = new Thickness(-30, 0, 0, 0);
contextMenu.Items.Add(separator);

var menuItem1 = new MenuItem();
menuItem1.Header = "显示主窗口";
menuItem1.Command = this.PushMainWindow2Top;
contextMenu.Items.Add(menuItem1);

var menuItem2 = new MenuItem();
menuItem2.Header = "退出程序";
menuItem2.Command = this.ExitCommand;
contextMenu.Items.Add(menuItem2);

notifyIcon.ContextMenu = contextMenu;

HandyControl.Controls.NotifyIcon.Register(notifyIcon.Token, notifyIcon);
notifyIcon.Init();

}`

Steps to reproduce the bug

详见描述

Expected behavior

No response

Screenshots

No response

NuGet package version

None

IDE

Visual Studio 2022

Framework type

.Net Framework 4.8

Windows version

No response

Additional context

No response

LickBag avatar Aug 16 '24 01:08 LickBag

公司不能上传文件,没法上传demo

LickBag avatar Aug 16 '24 01:08 LickBag