### WPF Tray Application Setup
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Example demonstrating how to set up a WPF application with a system tray icon. This typically involves initializing the TaskbarIcon control.
```xaml
```
--------------------------------
### WinUI Tray Application Setup
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Example demonstrating how to set up a WinUI application with a system tray icon. This typically involves initializing the TaskbarIcon control.
```xaml
```
--------------------------------
### TrayInfo Methods Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Demonstrates using utility methods from TrayInfo to get information about the system tray.
```csharp
var trayInfo = TrayInfo.Instance;
// Get the number of currently visible tray icons
int visibleIcons = trayInfo.VisibleTrayIcons;
// Check if the system is in a power-saving mode
bool isPowerSaving = trayInfo.IsPowerSavingModeEnabled;
// Get the current screen resolution
var screenSize = trayInfo.ScreenSize;
```
--------------------------------
### Console Application TrayIcon Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Basic setup for using TrayIcon in a .NET console application.
```csharp
using System;
using System.Threading;
using H.NotifyIcon;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting console app with tray icon...");
var trayIcon = new TrayIcon("MyConsoleApp")
{
ToolTipText = "Console App Running",
IconSource = new Icon("App.ico"),
Visible = true
};
trayIcon.Click += (s, e) => Console.WriteLine("Tray icon clicked!");
Console.WriteLine("Press Enter to exit...");
Console.ReadLine();
trayIcon.Dispose();
Console.WriteLine("Tray icon disposed. Exiting.");
}
}
```
--------------------------------
### Complete Message Window Event Handling Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
This example demonstrates how to initialize a TrayIcon, subscribe to various message window events (mouse, keyboard, balloon, taskbar, DPI), and handle them appropriately. Ensure the TrayIcon is properly disposed of after use.
```csharp
public class TrayMessageHandler
{
private readonly TrayIcon _trayIcon;
public TrayMessageHandler()
{
_trayIcon = new TrayIcon("MyApp");
}
public void Initialize()
{
_trayIcon.Create();
// Subscribe to all message window events
_trayIcon.MessageWindow.MouseEventReceived += OnMouseEvent;
_trayIcon.MessageWindow.KeyboardEventReceived += OnKeyboardEvent;
_trayIcon.MessageWindow.BalloonToolTipChanged += OnBalloonChanged;
_trayIcon.MessageWindow.TaskbarCreated += OnTaskbarCreated;
_trayIcon.MessageWindow.DpiChanged += OnDpiChanged;
}
private void OnMouseEvent(object? sender, MouseEvent evt, Point pt)
{
switch (evt)
{
case MouseEvent.IconLeftDoubleClick:
ShowMainWindow();
break;
case MouseEvent.IconRightMouseUp:
ShowContextMenu(pt);
break;
case MouseEvent.BalloonToolTipClicked:
HandleNotificationClick();
break;
}
}
private void OnKeyboardEvent(object? sender, KeyboardEvent evt, Point pt)
{
if (evt == KeyboardEvent.ContextMenu)
{
ShowContextMenu(pt);
}
}
private void OnBalloonChanged(object? sender, bool isVisible)
{
if (!isVisible)
{
// Notification was dismissed
}
}
private void OnTaskbarCreated(object? sender, EventArgs e)
{
// Taskbar restarted - icon will be automatically recreated
}
private void OnDpiChanged(object? sender, EventArgs e)
{
// DPI changed - re-render if needed
}
private void ShowMainWindow() { /* ... */ }
private void ShowContextMenu(Point pt) { /* ... */ }
private void HandleNotificationClick() { /* ... */ }
public void Cleanup()
{
_trayIcon.Dispose();
}
}
```
--------------------------------
### TaskbarIcon Code-Behind Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Example of how to create and configure a TaskbarIcon instance in C# code-behind, setting the ToolTipText property.
```csharp
var taskbarIcon = new TaskbarIcon();
taskbarIcon.ToolTipText = "My App";
```
--------------------------------
### Project File Example (Uno)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
A sample .NET project file configuration for an Uno application using H.NotifyIcon.
```xml
net8.0-windows10.0.19041.0;net8.0-android;net8.0-ios;net8.0-maccatalyst$(TargetFrameworks);net8.0-maccatalysttruetrueenableMyUnoAppAssets/App.ico
```
--------------------------------
### Graphics Backend Selection Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Demonstrates selecting a graphics backend for icon rendering in the project configuration.
```xml
SkiaSharp
```
--------------------------------
### Project File Example (Console)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
A sample .NET project file configuration for a Console application using H.NotifyIcon.
```xml
Exenet8.0enableenableMyConsoleApp
```
--------------------------------
### Project File Example (WPF)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
A sample .NET project file configuration for a WPF application using H.NotifyIcon.
```xml
WinExenet8.0-windowsenabletrueenableMyWpfAppApp.ico
```
--------------------------------
### Project File Example (MAUI)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
A sample .NET project file configuration for a MAUI application using H.NotifyIcon.
```xml
net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0-windows10.0.19041.0$(TargetFrameworks);net8.0-maccatalysttruetrueenableMyMauiAppResources/AppIcon/appicon.ico
```
--------------------------------
### NuGet Package Metadata Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Illustrates how NuGet package metadata can be configured for the H.NotifyIcon library.
```xml
H.NotifyIcon.WPF2.0.0Your NameSystem tray icon library for WPF.
```
--------------------------------
### EfficiencyModeUtilities Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Shows how to use EfficiencyModeUtilities to control background activity and resource usage.
```csharp
// Enable background activities for the application
EfficiencyModeUtilities.SetMode(EfficiencyMode.BackgroundActivities, true);
// Disable specific background tasks if needed
// EfficiencyModeUtilities.SetMode(EfficiencyMode.SomeSpecificTask, false);
// Check if a mode is enabled
bool isEnabled = EfficiencyModeUtilities.IsModeEnabled(EfficiencyMode.BackgroundActivities);
```
--------------------------------
### TaskbarIcon XAML Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Example of how to declare and configure a TaskbarIcon in XAML, setting the ToolTipText and IconSource properties.
```xml
```
--------------------------------
### MAUI Tray Icon Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Shows how to integrate a system tray icon into a .NET MAUI application.
```csharp
// In your MAUI App.xaml.cs or relevant code-behind:
public partial class App : Application
{
// ... other app initialization ...
public App()
{
InitializeComponent();
// Initialize TaskbarIcon for MAUI
// Note: MAUI integration might require platform-specific setup or handlers.
// Ensure the H.NotifyIcon.MAUI NuGet package is installed.
var taskbarIcon = new TaskbarIcon()
{
IconSource = new Icon("appicon.ico"), // Ensure icon is correctly placed
ToolTipText = "MAUI App Tray Icon"
};
// Further configuration or event handling would follow.
}
}
```
--------------------------------
### Project File Example (WinUI)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
A sample .NET project file configuration for a WinUI application using H.NotifyIcon.
```xml
WinExenet8.0-windows10.0.19041.010.0.17763.0x64win10-x64truetrueMyWinUIAppAssets/App.ico
```
--------------------------------
### Notification Status Icon Example (XAML)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/03-GeneratedIconSource.md
Example of creating a notification status indicator with specific foreground color and size.
```xml
```
--------------------------------
### Uno Platform Tray Icon Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Illustrates setting up a system tray icon within an Uno Platform application.
```csharp
// In your Uno App.xaml.cs or relevant code-behind:
public sealed partial class App : Application
{
// ... other app initialization ...
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
// ... existing launch logic ...
// Initialize TaskbarIcon for Uno Platform
var taskbarIcon = new TaskbarIcon()
{
IconSource = new Icon("Assets/App.ico"), // Ensure icon is in Assets folder
ToolTipText = "Uno App Tray Icon"
};
// TaskbarIcon might need to be attached or managed differently depending on Uno version and context.
// Refer to Uno-specific documentation or examples if needed.
}
}
```
--------------------------------
### WindowExtensions Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Illustrates using WindowExtensions to interact with the window's tray icon representation.
```csharp
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// Ensure the window has a TaskbarIcon instance associated with it
// For example, via XAML or code-behind initialization.
// Example: Force the icon to be created if it hasn't been already
this.ForceNotifyIconCreate();
// Example: Get the associated TaskbarIcon instance
// TaskbarIcon taskbarIcon = this.GetNotifyIcon();
}
}
```
--------------------------------
### Install H.NotifyIcon Packages
Source: https://github.com/havendv/h.notifyicon/blob/master/readme.md
Install the necessary H.NotifyIcon packages for your target platform using the NuGet Package Manager Console.
```powershell
Install-Package H.NotifyIcon.Wpf
Install-Package H.NotifyIcon.WinUI
Install-Package H.NotifyIcon.Uno
Install-Package H.NotifyIcon.Uno.WinUI
# If you need other platforms, you can use this Core library -
# it allows you to make NotifyIcon even in a console application.
Install-Package H.NotifyIcon
```
--------------------------------
### MessageWindow Create Method Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Shows how to create and initialize the internal message window used for event handling.
```csharp
var messageWindow = MessageWindow.Create("MyUniqueAppId");
messageWindow.Show(); // Make the window visible or hidden as needed
// Subscribe to events on the messageWindow instance
messageWindow.MessageReceived += OnMessageReceived;
// ... later, when done ...
messageWindow.Close();
```
--------------------------------
### Complete Window Management Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/05-utilities.md
Demonstrates a comprehensive approach to managing window visibility and taskbar presence within a ViewModel, suitable for tray applications.
```csharp
public class TrayApplicationViewModel
{
private Window _mainWindow;
public TrayApplicationViewModel(Window mainWindow)
{
_mainWindow = mainWindow;
}
// Hide app to system tray with efficiency mode
public void MinimizeToTray()
{
_mainWindow.HideInTaskbar();
_mainWindow.Hide(enableEfficiencyMode: true);
}
// Show app and restore full performance
public void RestoreFromTray()
{
_mainWindow.Show(disableEfficiencyMode: true);
_mainWindow.ShowInTaskbar();
_mainWindow.Activate();
}
// Toggle visibility
public void ToggleVisibility()
{
if (_mainWindow.IsVisible)
MinimizeToTray();
else
RestoreFromTray();
}
}
```
--------------------------------
### TaskbarIcon Popup Activation Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of setting the popup activation mode for a TaskbarIcon in XAML. This controls how the user can interact with the icon to show its associated menu.
```xml
```
--------------------------------
### TaskbarIcon Efficiency Mode Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Demonstrates how to enable and configure Efficiency Mode for the TaskbarIcon to reduce resource consumption.
```csharp
var taskbarIcon = new TaskbarIcon();
// Enable Efficiency Mode
taskbarIcon.EnableWin32EfficiencyMode = true;
// Optionally, configure specific settings if available via EfficiencyModeUtilities
// EfficiencyModeUtilities.SetMode(EfficiencyMode.BackgroundActivities, true);
// ... rest of the configuration
```
--------------------------------
### Basic XAML Setup (WPF)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Sets up a TaskbarIcon in XAML for a WPF application. Configures tooltips, icon sources, and context menu/popup activations.
```xml
```
--------------------------------
### TaskbarIcon MenuActivation Property Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Example showing how to configure the MenuActivation property for a TaskbarIcon in XAML to change when the context menu is displayed.
```xml
```
--------------------------------
### Emoji Icon Example (XAML)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/03-GeneratedIconSource.md
Shows how to use an emoji as the text for the GeneratedIconSource.
```xml
```
--------------------------------
### TrayIcon Constructor Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Demonstrates the basic usage of the TrayIcon constructor for low-level interop and console applications.
```csharp
// For Windows interop and console apps
var trayIcon = new TrayIcon("MyUniqueAppId");
trayIcon.ToolTipText = "My Tooltip";
trayIcon.IconSource = new Icon("App.ico");
trayIcon.Visible = true;
// ... handle events and dispose when done
```
--------------------------------
### TaskbarIcon ContextMenuMode Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of setting the context menu rendering mode for a TaskbarIcon in XAML. This affects how the context menu appears in WinUI/Uno applications.
```xml
```
--------------------------------
### Simple Text Badge Example (XAML)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/03-GeneratedIconSource.md
Demonstrates setting up a basic text badge using GeneratedIconSource within a TaskbarIcon.
```xml
```
--------------------------------
### TaskbarIcon IconSource Property Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Example demonstrating how to set the IconSource property for a TaskbarIcon in XAML, specifying a resource path for the icon.
```xml
```
--------------------------------
### MSBuild Property Configuration Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Shows how to configure H.NotifyIcon build properties within an MSBuild project file.
```xml
WinExenet8.0-windowstruetrueDefaulttrue
```
--------------------------------
### TrayIcon Method Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Shows how to use public methods of the TrayIcon class, such as updating the icon or tooltip.
```csharp
var trayIcon = new TrayIcon("MyUniqueAppId");
// Update icon dynamically
trayIcon.IconSource = new Icon("NewIcon.ico");
// Update tooltip text
trayIcon.ToolTipText = "Status updated";
// Show a notification balloon
trayIcon.ShowBalloonTip("Notification Title", "This is the message.", BalloonTipIcon.Info);
// Hide the icon
trayIcon.Visible = false;
// Dispose the icon when application closes
trayIcon.Dispose();
```
--------------------------------
### Code-Behind Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Handles the left-click command for a TaskbarIcon in C# code-behind. Toggles the visibility of the main window.
```csharp
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TrayIcon.LeftClickCommand = new RelayCommand(() =>
{
if (IsVisible)
Hide();
else
Show();
});
}
private void ShowWindow_Click(object sender, RoutedEventArgs e)
{
Show();
WindowState = WindowState.Normal;
Activate();
}
}
```
--------------------------------
### Build Feature Flags Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Shows how to enable or disable build features like trimming and Ahead-of-Time (AOT) compilation.
```xml
truetruetrue
```
--------------------------------
### TrayIcon Event Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Demonstrates how to subscribe to and handle events raised by the TrayIcon class, such as mouse clicks.
```csharp
var trayIcon = new TrayIcon("MyUniqueAppId");
trayIcon.Click += (sender, args) => {
// Handle single click
MessageBox.Show("Tray icon clicked!");
};
trayIcon.DoubleClick += (sender, args) => {
// Handle double click
MessageBox.Show("Tray icon double-clicked!");
};
trayIcon.MouseUp += (sender, args) => {
// Handle mouse button up event
if (args.ChangedButton == MouseButton.Right) {
// Show context menu
}
};
trayIcon.MouseMove += (sender, args) => {
// Handle mouse move event
};
```
--------------------------------
### Set Process Priority Class Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of setting the process priority class to Idle using EfficiencyModeUtilities. This is often used for background tray icon applications to minimize resource usage.
```csharp
EfficiencyModeUtilities.SetProcessPriorityClass(ProcessPriorityClass.Idle);
```
--------------------------------
### TrayIcon Property Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Illustrates setting various properties on the TrayIcon class for customization.
```csharp
var trayIcon = new TrayIcon("MyUniqueAppId");
trayIcon.ToolTipText = "Application running";
trayIcon.IconSource = new Icon("App.ico");
trayIcon.Visible = true;
trayIcon.AnimateOnActivate = true;
trayIcon.IsDesignMode = false;
// ... further configuration
```
--------------------------------
### MessageWindow Event Handling Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Demonstrates subscribing to and handling events from the MessageWindow, which is central to the library's event system.
```csharp
public void SubscribeToEvents(MessageWindow messageWindow)
{
messageWindow.TrayMouseDoubleClick += OnTrayDoubleClick;
messageWindow.TrayBalloonTipClosed += OnBalloonTipClosed;
messageWindow.TrayMenuItemClick += OnMenuItemClick;
}
private void OnTrayDoubleClick(object sender, RoutedEventArgs e) { /* Handle double click */ }
private void OnBalloonTipClosed(object sender, RoutedEventArgs e) { /* Handle balloon tip closed */ }
private void OnMenuItemClick(object sender, RoutedEventArgs e) { /* Handle menu item click */ }
```
--------------------------------
### Gradient Icon Example (XAML)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/03-GeneratedIconSource.md
Illustrates using LinearGradientBrush for both foreground and background to create a gradient effect.
```xml
```
--------------------------------
### TaskbarIcon ForceCreate Method
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Example of using the ForceCreate() method on TaskbarIcon, which can be useful for ensuring the icon is created immediately.
```csharp
var taskbarIcon = new TaskbarIcon();
// ... configure taskbarIcon properties ...
taskbarIcon.ForceCreate(); // Ensures the icon is created even if not immediately visible or bound.
```
--------------------------------
### MenuActivation Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets or sets the activation mode for displaying the context menu, such as right-click or left-click.
```APIDOC
## MenuActivation
### Description
Gets or sets when the context menu is displayed.
### Remarks
Determines trigger: `RightClick`, `LeftClick`, `DoubleClick`, `LeftOrRightClick`, etc.
### Example:
```xml
```
### Property
- **MenuActivation** (PopupActivationMode) - Default: RightClick
```
--------------------------------
### Efficiency Mode Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Demonstrates controlling efficiency mode for window visibility. Hides the window with efficiency mode enabled, and shows it with efficiency mode disabled.
```csharp
// Hide window to background with efficiency mode enabled
mainWindow.Hide(enableEfficiencyMode: true);
// Show window and disable efficiency mode
mainWindow.Show(disableEfficiencyMode: true);
```
--------------------------------
### Event Processing Model Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Illustrates the internal event processing model, showing how messages are received and dispatched.
```csharp
// This is a conceptual example of the internal event processing.
// Actual implementation is within the MessageWindow class.
// When a system message arrives:
// 1. MessageWindow receives the message (e.g., WM_LBUTTONUP).
// 2. It identifies the message type and associated data.
// 3. It translates the system message into a .NET event argument.
// 4. It raises the corresponding .NET event (e.g., TrayMouseDoubleClick).
// 5. Subscribers to that event are notified.
```
--------------------------------
### Rounded Badge Icon Example (XAML)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/03-GeneratedIconSource.md
Demonstrates creating a rounded badge with border and specific colors.
```xml
```
--------------------------------
### WinUI/Uno Setup
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Configures a TaskbarIcon in XAML for WinUI or Uno Platform applications. Specifies tooltip, icon source, and context flyout mode.
```xml
```
--------------------------------
### Create MessageWindow and Get Handle
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
Demonstrates how to manually create an instance of MessageWindow and retrieve its native window handle. The handle will be non-zero after successful creation.
```csharp
var messageWindow = new MessageWindow();
messageWindow.Create();
var handle = messageWindow.Handle; // Non-zero after successful creation
```
--------------------------------
### GeneratedIcon Properties Example
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/README.md
Illustrates customizing a dynamically generated icon using various properties like badges, text, and gradients.
```csharp
var generatedIcon = new GeneratedIcon
{
Source = new Icon("App.ico"), // Base icon
Badge = new Badge { Text = "99+", Background = Brushes.Red },
Overlay = new Overlay { Content = "!", Foreground = Brushes.White },
Text = new TextBlock { Text = "Status", Foreground = Brushes.Black },
Gradient = new Gradient { Angle = 45, Stops = { new GradientStop(Colors.Yellow, 0), new GradientStop(Colors.Orange, 1) } }
};
// Assign to TaskbarIcon or TrayIcon
// taskbarIcon.IconSource = generatedIcon;
```
--------------------------------
### Version Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Gets the icon version currently in use. This property reflects the OS capability level.
```APIDOC
## GET /Version
### Description
Gets the icon version currently in use. Updated after `Create()`.
### Endpoint
/Version
### Response
#### Success Response (200)
- **Version** (IconVersion) - Read-only - The current icon version.
### Remarks
Reflects the OS capability level: `Win95`, `Win2000`, or `Vista` (full tooltip support). See `IconVersion` enum for details.
```
--------------------------------
### Check for Vista Icon Version Capabilities
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of checking if the current icon version supports custom tooltips, which is available for Vista and later.
```csharp
if (trayIcon.Version == IconVersion.Vista)
{
// Can use custom tooltips
}
```
--------------------------------
### SupportsCustomToolTips Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Gets a value indicating whether custom tooltips are supported. This is true only for Vista or later versions.
```APIDOC
## GET /SupportsCustomToolTips
### Description
Gets a value indicating whether custom tooltips are supported.
### Endpoint
/SupportsCustomToolTips
### Response
#### Success Response (200)
- **SupportsCustomToolTips** (bool) - Read-only - Indicates if custom tooltips are supported.
### Remarks
Returns true only for `Version == IconVersion.Vista`. Requires Windows Vista or later.
```
--------------------------------
### Generate Unique Guid from String
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Generates a deterministic Guid from a string using SHA256 hashing. Always returns the same Guid for the same input, useful for consistent identifiers.
```csharp
public static Guid CreateUniqueGuidFromString(string input)
```
--------------------------------
### WinUI/Uno - Context Menu
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/INDEX.md
Configure a TaskbarIcon in WinUI or Uno applications to display a context menu on right-click. This example shows how to define menu items with associated click events.
```xml
```
--------------------------------
### Generate Unique Guid for Process Path
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Generates a unique Guid based on the current process path, with an optional postfix. This is useful for creating consistent icon identifiers without manual Guid generation, allowing for multiple icons within the same application.
```csharp
public static Guid CreateUniqueGuidForProcessPath(string? postfix = null)
```
--------------------------------
### Handle Taskbar Icon Keyboard Events
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of subscribing to and handling keyboard events received when the taskbar icon has focus, such as showing a context menu.
```csharp
messageWindow.KeyboardEventReceived += (sender, keyEvent) =>
{
if (keyEvent == KeyboardEvent.ContextMenu)
{
// Show context menu
}
};
```
--------------------------------
### Set Process Quality of Service Level
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of how to set the process quality of service level using the EfficiencyModeUtilities class. This is useful for optimizing application performance and power consumption.
```csharp
EfficiencyModeUtilities.SetProcessQualityOfServiceLevel(QualityOfServiceLevel.Eco);
```
--------------------------------
### UpdateId(Guid id) Method
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Updates the taskbar icon's unique identifier at runtime. If the icon is currently created, it will be removed and recreated with the new Guid.
```APIDOC
## PUT /UpdateId
### Description
Updates the taskbar icon's unique identifier at runtime.
### Method
PUT
### Endpoint
/UpdateId
### Parameters
#### Query Parameters
- **id** (Guid) - Required - New unique identifier
### Remarks
If the icon is currently created, it will be removed and recreated with the new Guid. Supported on Windows 5.1.2600+.
### Exceptions
- **ObjectDisposedException**: Instance has been disposed
- **InvalidOperationException**: Update failed
```
--------------------------------
### Build MAUI Sample App
Source: https://github.com/havendv/h.notifyicon/blob/master/CLAUDE.md
Builds the MAUI sample application for Windows. Specifies the target framework for Windows development.
```bash
dotnet build src/apps/H.NotifyIcon.Apps.Maui/H.NotifyIcon.Apps.Maui.csproj -f net9.0-windows10.0.19041.0
```
--------------------------------
### Run WPF Sample App
Source: https://github.com/havendv/h.notifyicon/blob/master/CLAUDE.md
Executes the WPF sample application. This demonstrates how to integrate H.NotifyIcon within a WPF project.
```bash
dotnet run --project src/apps/H.NotifyIcon.Apps.Wpf/H.NotifyIcon.Apps.Wpf.csproj
```
--------------------------------
### Initialize TrayIcon with a specific Guid
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Use this constructor to initialize a taskbar icon with a specific unique identifier. The Guid must be fixed and unique per application icon, as Windows associates it with the executable path.
```csharp
public TrayIcon(Guid id)
```
```csharp
var trayId = Guid.Parse("12345678-1234-1234-1234-123456789012");
var trayIcon = new TrayIcon(trayId);
```
--------------------------------
### Configure Tray Icon GUID Persistence
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/00-quick-start.md
Manage the persistence of tray icon settings like position and name. Options include auto-generation based on path, explicit GUID setting, or using a custom name.
```csharp
// Option A: Let it auto-generate
var trayIcon = new TrayIcon(); // Uses path-based hash
// Option B: Explicit fixed Guid
var trayIcon = new TrayIcon(new Guid("12345678-..."));
// Option C: Use custom name
var trayIcon = new TrayIcon("MyApplicationTray");
```
--------------------------------
### IsDisposed Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Gets a value indicating whether this instance has been disposed.
```APIDOC
## GET /IsDisposed
### Description
Gets a value indicating whether this instance has been disposed.
### Endpoint
/IsDisposed
### Response
#### Success Response (200)
- **IsDisposed** (bool) - Read-only - True if the instance has been disposed, false otherwise.
### Remarks
Applicable to all platforms.
```
--------------------------------
### Manual MessageWindow Creation and Event Subscription
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
Shows how to manually create a MessageWindow instance and subscribe to its events.
```csharp
var messageWindow = new MessageWindow();
messageWindow.Create();
// Now subscribe to events
messageWindow.MouseEventReceived += OnMouseEvent;
```
--------------------------------
### Run Console Sample App
Source: https://github.com/havendv/h.notifyicon/blob/master/CLAUDE.md
Executes the Console application sample. This demonstrates using H.NotifyIcon in a non-GUI environment.
```bash
dotnet run --project src/apps/H.NotifyIcon.Apps.Console/H.NotifyIcon.Apps.Console.csproj
```
--------------------------------
### Create Tray Icon and Check Status
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Demonstrates how to create a tray icon and verify its successful creation. This is a fundamental step before interacting with the icon.
```csharp
trayIcon.Create();
if (trayIcon.IsCreated)
{
Console.WriteLine("Icon created successfully");
}
```
--------------------------------
### Handling ChangeToolTipStateRequest Event
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
Example of how to subscribe to the ChangeToolTipStateRequest event to close a custom tooltip when requested.
```csharp
trayIcon.MessageWindow.ChangeToolTipStateRequest += (sender, isVisible) =>
{
if (!isVisible)
{
// Close custom tooltip
tooltipWindow.Hide();
}
};
```
--------------------------------
### Set Release Notes and Build
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/06-configuration.md
Sets the PACKAGE_RELEASE_NOTES environment variable and builds the project in Release configuration.
```bash
set PACKAGE_RELEASE_NOTES=- Fixed icon update on taskbar restart
dotnet build -c Release
```
--------------------------------
### Visibility Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets or sets the visibility state of the taskbar icon, allowing it to be shown or hidden.
```APIDOC
## Visibility
### Description
Gets or sets the visibility state of the icon.
### Remarks
Set to `Visibility.Hidden` to hide without removing the icon.
### Property
- **Visibility** (Visibility) - Default: Visible
```
--------------------------------
### Icon Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets or sets the System.Drawing.Icon to be displayed, allowing for dynamic icon switching at runtime.
```APIDOC
## Icon
### Description
Gets or sets a System.Drawing.Icon to be displayed (for dynamic icon switching).
### Remarks
Use this property to dynamically change the displayed icon at runtime. The icon is automatically disposed if replaced.
### Property
- **Icon** (Icon) - Default: null
```
--------------------------------
### IsCreated Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets a value indicating whether the taskbar icon has been successfully created and is active.
```APIDOC
## IsCreated
### Description
Gets a value indicating whether the taskbar icon has been created.
### Remarks
Reflects the state of `TrayIcon.IsCreated`. The icon is typically created automatically when the control is loaded.
### Property
- **IsCreated** (bool) - Read-only
```
--------------------------------
### Run WinUI Sample App
Source: https://github.com/havendv/h.notifyicon/blob/master/CLAUDE.md
Executes the WinUI sample application. Requires a specific Runtime Identifier (RID) such as x64, x86, or arm64.
```bash
dotnet run --project src/apps/H.NotifyIcon.Apps.WinUI/H.NotifyIcon.Apps.WinUI.csproj
```
--------------------------------
### Create() Method
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Creates the taskbar icon and registers it with Windows. Automatically creates a MessageWindow if WindowHandle is not set.
```APIDOC
## POST /Create
### Description
Creates the taskbar icon and registers it with Windows.
### Method
POST
### Endpoint
/Create
### Remarks
If already created, this method returns without action. Creates a `MessageWindow` automatically if `WindowHandle` is not set. Retrieves the most recent icon version from the OS.
### Example
```csharp
trayIcon.Create();
if (trayIcon.IsCreated)
{
Console.WriteLine("Icon created successfully");
}
```
### Exceptions
- **InvalidOperationException**: Icon creation failed (Windows API error)
```
--------------------------------
### Build Uno Project
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/06-configuration.md
Builds the Uno project for H.NotifyIcon. Use this command to compile the Uno platform-specific library.
```bash
dotnet build src/libs/H.NotifyIcon.Uno/H.NotifyIcon.Uno.csproj -c Release
```
--------------------------------
### Troubleshooting: Ensuring Message Window Creation and Version Check
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
If events are not firing, verify that the message window has been created using `Create()` and check the icon's version. Subscribe to events after ensuring the window is ready.
```csharp
if (!messageWindow.IsCreated)
messageWindow.Create();
// Check version
Console.WriteLine($"Icon version: {messageWindow.Version}");
```
--------------------------------
### Handling DpiChanged Event
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
Example of subscribing to the DpiChanged event to refresh the taskbar icon by removing and recreating it.
```csharp
trayIcon.MessageWindow.DpiChanged += (sender, args) =>
{
// Refresh any DPI-dependent rendering
trayIcon.TryRemove();
trayIcon.Create();
};
```
--------------------------------
### Build MAUI Project
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/06-configuration.md
Builds the MAUI project for H.NotifyIcon. Use this command to compile the MAUI platform-specific library.
```bash
dotnet build src/libs/H.NotifyIcon.Maui/H.NotifyIcon.Maui.csproj -c Release
```
--------------------------------
### Handling TaskbarCreated Event
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
Example of subscribing to the TaskbarCreated event to log a message indicating the taskbar has restarted.
```csharp
trayIcon.MessageWindow.TaskbarCreated += (sender, args) =>
{
Console.WriteLine("Taskbar restarted - icon will be recreated");
};
```
--------------------------------
### Handling BalloonToolTipChanged Event
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/07-MessageWindow.md
Example of subscribing to the BalloonToolTipChanged event to log when a balloon notification is shown or hidden.
```csharp
trayIcon.MessageWindow.BalloonToolTipChanged += (sender, isVisible) =>
{
Console.WriteLine($"Balloon {(isVisible ? "shown" : "hidden")}");
};
```
--------------------------------
### UseStandardTooltip Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Gets or sets whether the standard OS tooltip should be shown with version 4 icons.
```APIDOC
## GET/PUT /UseStandardTooltip
### Description
Gets or sets whether the standard OS tooltip should be shown with version 4 icons.
### Endpoint
/UseStandardTooltip
### Response
#### Success Response (200)
- **UseStandardTooltip** (bool) - Read-only - Default: true. Indicates if the standard tooltip is used.
### Remarks
Default value is true. Applicable for Windows 5.1.2600+.
```
--------------------------------
### Build Specific Platform Library
Source: https://github.com/havendv/h.notifyicon/blob/master/CLAUDE.md
Builds a single, specified platform library. This is useful for targeting a particular platform like WPF.
```bash
dotnet build src/libs/H.NotifyIcon.Wpf/H.NotifyIcon.Wpf.csproj --configuration Release
```
--------------------------------
### Build Specific Platform Command (WPF)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/06-configuration.md
Builds the H.NotifyIcon.Wpf project in Release configuration.
```bash
# WPF
dotnet build src/libs/H.NotifyIcon.Wpf/H.NotifyIcon.Wpf.csproj -c Release
```
--------------------------------
### IconSource Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets or sets the source for the icon, which can be a static image resource or a dynamically generated source.
```APIDOC
## IconSource
### Description
Gets or sets the icon source (can be a static image resource or `GeneratedIconSource`).
### Remarks
Accepts any `ImageSource` (e.g., `BitmapImage`, `GeneratedIconSource`). Changes are reflected automatically.
### Example:
```xml
```
### Property
- **IconSource** (ImageSource) - Default: null
```
--------------------------------
### Build All Libraries
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/INDEX.md
This PowerShell command builds all .csproj files found in the 'src/libs' directory with the 'Release' configuration.
```powershell
# All libraries
Get-ChildItem -Path src/libs -Recurse -Filter *.csproj | \
ForEach-Object { dotnet build $_.FullName --configuration Release }
```
--------------------------------
### Id Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets or sets the unique identifier for this taskbar icon, which is used by Windows for settings persistence.
```APIDOC
## Id
### Description
Gets or sets the unique identifier for this taskbar icon.
### Remarks
Modify before the control is created to use a fixed identifier. Windows associates this Guid with the executable path for settings persistence.
### Property
- **Id** (Guid) - Default: Auto-generated
```
--------------------------------
### Build All Libraries
Source: https://github.com/havendv/h.notifyicon/blob/master/CLAUDE.md
Builds all .csproj files found recursively within the src/libs directory. Use this command to compile all platform-specific libraries and core components.
```powershell
Get-ChildItem -Path src/libs -Recurse -Filter *.csproj | ForEach-Object { dotnet build $_.FullName --configuration Release }
```
--------------------------------
### Initialize Thickness Struct
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Demonstrates initializing the Thickness struct with different values for margins or padding. A single value applies to all sides, while four values specify left, top, right, and bottom respectively.
```csharp
Thickness margin = new Thickness(10); // All sides: 10
Thickness padding = new Thickness(10, 5, 10, 5); // L=10, T=5, R=10, B=5
```
--------------------------------
### Show
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/05-utilities.md
Shows the window and optionally disables Efficiency Mode. This method has platform-specific implementations for WPF, WinUI/Uno, and MAUI.
```APIDOC
## Show(Window window, bool disableEfficiencyMode = true)
### Description
Shows the window and optionally disables Efficiency Mode. This method has platform-specific implementations for WPF, WinUI/Uno, and MAUI.
### Method
`public static void Show(
this Window window,
bool disableEfficiencyMode = true
)`
### Parameters
#### Path Parameters
- **window** (Window) - Required - Extension target (the window to show)
- **disableEfficiencyMode** (bool) - Optional - Default: true - Disable Efficiency Mode after showing
### Remarks
- **Platform behavior:**
- **WPF:** Calls `Window.Show()`
- **WinUI/Uno:** Calls `WindowUtilities.ShowWindow()` via window handle
- **MAUI:** Uses handler's platform view
- **Efficiency Mode:**
- Only disabled if OS version is Windows 10.0.16299 or later
- Automatically calls `EfficiencyModeUtilities.SetEfficiencyMode(false)`
- Restores full performance when window is visible
### Example
```csharp
// Show window and restore full performance
mainWindow.Show(disableEfficiencyMode: true);
// Or just show without changing efficiency mode
mainWindow.Show(disableEfficiencyMode: false);
```
```
--------------------------------
### Update Taskbar Icon Visibility
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/04-types.md
Example of updating the taskbar icon's visibility using the IconVisibility enum.
```csharp
trayIcon.UpdateVisibility(IconVisibility.Hidden);
```
--------------------------------
### ToolTipText Property
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/02-TaskbarIcon.md
Gets or sets the standard system tooltip text that appears when the user hovers over the taskbar icon.
```APIDOC
## ToolTipText
### Description
Gets or sets the standard system tooltip text displayed on hover.
### Remarks
Limited to ~260 characters. For rich tooltips, use `TrayToolTip` property instead.
### Property
- **ToolTipText** (string) - Default: ""
```
--------------------------------
### CreateUniqueGuidFromString
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/01-TrayIcon.md
Generates a unique and deterministic Guid from a given string using SHA256 hashing. This is useful for deriving consistent identifiers.
```APIDOC
## CreateUniqueGuidFromString(string input)
### Description
Generates a unique Guid from a string using SHA256 hashing.
### Method
`CreateUniqueGuidFromString`
### Parameters
#### Path Parameters
- **input** (string) - Yes - String to hash
### Returns
A deterministic Guid derived from the input string.
### Exceptions
- **ArgumentNullException**: input is null
- **ArgumentException**: input is empty or whitespace
```
--------------------------------
### Build Specific Platform Command (WinUI)
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/06-configuration.md
Builds the H.NotifyIcon.WinUI project in Release configuration.
```bash
# WinUI
dotnet build src/libs/H.NotifyIcon.WinUI/H.NotifyIcon.WinUI.csproj -c Release
```
--------------------------------
### Configure Graphics Backend
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/00-quick-start.md
Select the graphics library for icon generation. Defaults to System.Drawing, but SkiaSharp can be used as an alternative.
```xml
System.Drawing
```
--------------------------------
### Uno Platform Application Project File
Source: https://github.com/havendv/h.notifyicon/blob/master/_autodocs/06-configuration.md
Configures an Uno Platform project, targeting .NET and including the H.NotifyIcon.Uno package.
```xml
net9.0
```