Drastic.Tray 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Drastic.Tray --version 1.0.7                
NuGet\Install-Package Drastic.Tray -Version 1.0.7                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Drastic.Tray" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Drastic.Tray --version 1.0.7                
#r "nuget: Drastic.Tray, 1.0.7"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Drastic.Tray as a Cake Addin
#addin nuget:?package=Drastic.Tray&version=1.0.7

// Install Drastic.Tray as a Cake Tool
#tool nuget:?package=Drastic.Tray&version=1.0.7                

NuGet Version License

Drastic.Tray

Drastic.Tray is a straightforward API for creating tray icons, designed for dotnet Mac Catalyst, macOS, and WinUI applications.

animation

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
1.0.9 996 12/31/2022
1.0.8 762 12/27/2022
1.0.7 740 12/26/2022
1.0.6 722 12/25/2022
1.0.5 730 12/24/2022
1.0.4 756 12/24/2022
1.0.3 736 12/23/2022
1.0.2 735 12/23/2022
1.0.1 722 12/23/2022
1.0.0 734 12/22/2022