### 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-maccatalyst true true enable MyUnoApp Assets/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 Exe net8.0 enable enable MyConsoleApp ``` -------------------------------- ### 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 WinExe net8.0-windows enable true enable MyWpfApp App.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-maccatalyst true true enable MyMauiApp Resources/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.WPF 2.0.0 Your Name System 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 WinExe net8.0-windows10.0.19041.0 10.0.17763.0 x64 win10-x64 true true MyWinUIApp Assets/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