Drastic.Tray
1.0.4
See the version list below for details.
dotnet add package Drastic.Tray --version 1.0.4
NuGet\Install-Package Drastic.Tray -Version 1.0.4
<PackageReference Include="Drastic.Tray" Version="1.0.4" />
paket add Drastic.Tray --version 1.0.4
#r "nuget: Drastic.Tray, 1.0.4"
// Install Drastic.Tray as a Cake Addin #addin nuget:?package=Drastic.Tray&version=1.0.4 // Install Drastic.Tray as a Cake Tool #tool nuget:?package=Drastic.Tray&version=1.0.4
Drastic.Tray
Drastic.Tray is a straightforward API for creating tray icons, designed for dotnet Mac Catalyst, macOS, and WinUI applications.
IMPORTANT
For this to work on Mac Catalyst, we are using Objective-C Selectors for directly accessing AppKit APIs from UIKit. These are private, and are frowd upon by Apple. You may have issues publishing apps using this library within the Mac App Store. While it should "work" it is best seen as experimental.
How To Use
Usage between macOS, Catalyst, and Windows is similar.
var menuItems = new List<TrayMenuItem>();
var trayImage = new TrayImage(NSImage.ImageNamed("TrayIcon.ico")!);
menuItems.Add(new TrayMenuItem("Hello!", trayImage, async () => { }, "h"));
menuItems.Add(new TrayMenuItem("From!", trayImage, async () => { }, "f"));
menuItems.Add(new TrayMenuItem("MacOS!", trayImage, async () => { }, "m", NSEventModifierMask.ControlKeyMask | NSEventModifierMask.CommandKeyMask));
var trayIcon = new Drastic.Tray.TrayIcon("Tray Icon", trayImage, menuItems);
trayIcon.LeftClicked += (object? sender, TrayClickedEventArgs e) => trayIcon.OpenMenu();
trayIcon.RightClicked += (object? sender, TrayClickedEventArgs e) => { };
Create a TrayImage
. This requires either an NSImage
or UIImage
(Which gets turned back into an NSImage
). If you wish, create a list of TrayMenuItem
. These can then be invoked in the tray icon with trayIcon.OpenMenu()
.
When you create the TrayIcon
, it should automatically appear in the Mac Tray.
After you create the icon, you can attach to LeftClicked
and RightClicked
to handle accessing the respected events on the button.
You can have as many TrayIcon's as allowed by the system. However, you should probably limit yourself to one, unless you hate your users. But hey, you do you, mythical developer.
IMPORTANT WINUI NOTE
If you use the default TrayMenuItem
lists and add them to the TrayIcon
, they will always open with the right mouse button. This is the default for the underlying WinForms control. If you wish to open it yourself or use it on Left Click, you should handle the menu creation yourself and use the LeftClicked
or RightClicked
event.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-maccatalyst15.4 is compatible. net7.0-macos was computed. net7.0-macos12.3 is compatible. net7.0-tvos was computed. net7.0-windows was computed. net7.0-windows10.0.19041 is compatible. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
-
net7.0-maccatalyst15.4
- No dependencies.
-
net7.0-macos12.3
- No dependencies.
-
net7.0-windows10.0.19041
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Drastic.Tray:
Package | Downloads |
---|---|
Drastic.TrayWindow
Create popup windows from tray icons for macOS, Mac Catalyst, and WinUI apps. |
|
Drastic.TrayWindow.Maui
Create cross-platform Mac Catalyst and WinUI Tray Window views using MAUI. |
GitHub repositories
This package is not used by any popular GitHub repositories.