Skip to content

How to create TrayIcon programmatically? #17764

Answered by tobyfirth
wl2776 asked this question in Q&A
Discussion options

You must be logged in to vote

You can do something like this.

var icons = new TrayIcons
{
	new TrayIcon
	{
		Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://SmartbinderUI/Assets/avalonia-logo.ico")))),
		Menu = [
			new NativeMenuItem("Settings")
			{
				Menu = new NativeMenu
				{
					new NativeMenuItem("Option 1"),
					new NativeMenuItem("Option 2"),
					new NativeMenuItemSeparator(),
					new NativeMenuItem("Option 3")
				}
			}
		]
	}
};

TrayIcon.SetIcons(Application.Current, icons);

And to remove it.

TrayIcon.SetIcons(Application.Current, null);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by wl2776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants