HandyOrg / HandyOrg/HandyControl
Bug title
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.2k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the HandyControl.Controls.NotifyIcon XAML initialization and the Register/Init paths shown in the issue. Reproduce the behavior by reconnecting through MSTSC, compare it with the C# InitTray setup, and verify that repeated connections no longer create duplicate tray icons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100