Drastic.Tray
1.0.0
See the version list below for details.
dotnet add package Drastic.Tray --version 1.0.0
NuGet\Install-Package Drastic.Tray -Version 1.0.0
<PackageReference Include="Drastic.Tray" Version="1.0.0" />
paket add Drastic.Tray --version 1.0.0
#r "nuget: Drastic.Tray, 1.0.0"
// Install Drastic.Tray as a Cake Addin #addin nuget:?package=Drastic.Tray&version=1.0.0 // Install Drastic.Tray as a Cake Tool #tool nuget:?package=Drastic.Tray&version=1.0.0
Drastic.Tray
Drastic.Tray is a straightforward API for creating tray icons, designed for dotnet Mac Catalyst and macOS 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 and Catalyst 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(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.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0-maccatalyst15.4 is compatible. net7.0-macos12.3 is compatible. net8.0-maccatalyst was computed. net8.0-macos was computed. |
-
net7.0-maccatalyst15.4
- No dependencies.
-
net7.0-macos12.3
- 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.