H.NotifyIcon: Creating a TaskbarIcon in-code causes windows to treat each instance as unique

Describe the bug

I may be doing something incorrectly, if so feel free to correct me.

I’m creating a new TaskbarIcon in-code by using

taskbarIcon = new TaskbarIcon();
taskbarIcon.Icon = new System.Drawing.Icon("Assets/(The icon)");
taskbarIcon.ToolTipText = "(tooltip name)";

But this creates a new “unique” icon every time, which floods settings and doesn’t let the user choose if the icon should be in the overflow menu or not.

Steps to reproduce the bug

  1. Create a TaskbarIcon manually, using the code described above
  2. Launch the app multiple times
  3. Check “Other system tray icons” in settings

Expected behavior

Only one entry for the application

Screenshots

image

NuGet package version

2.0.24

Platform

WinUI

IDE

Visual Studio 2022

Additional context

I may be doing something wrong, or creating a TaskbarIcon in-code may be fully unsupported.

It is quite possible there’s simply some ID property or something I’m not aware I need to set.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

This may also be a Windows 11 bug which Microsoft needs to fix.

I recommend making another issue to track this if you would like; you may feel free to use my recording in it if you do so.

Yes of course. The main problem I want to solve is so that the user does not have to set a fixed GUID on a permanent basis (but with such an option if necessary). I need to check if Assembly.GetEntryAssembly() returns the same Guid for the same application and different for different applications so that I can use this as the default behavior.