Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nullsoftware/trayicon
Tray Icon for WPF Application. Has wrapper for WPF ContexMenu.
https://github.com/nullsoftware/trayicon
balloon notifier notify notify-icon notifyicon tray tray-icon tray-menu trayicon win32 wpf
Last synced: about 4 hours ago
JSON representation
Tray Icon for WPF Application. Has wrapper for WPF ContexMenu.
- Host: GitHub
- URL: https://github.com/nullsoftware/trayicon
- Owner: nullsoftware
- License: mit
- Created: 2021-10-02T17:22:31.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-13T10:08:20.000Z (8 months ago)
- Last Synced: 2024-11-06T13:18:35.346Z (1 day ago)
- Topics: balloon, notifier, notify, notify-icon, notifyicon, tray, tray-icon, tray-menu, trayicon, win32, wpf
- Language: C#
- Homepage:
- Size: 185 KB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)
[![](https://img.shields.io/nuget/vpre/TrayIcon)](https://www.nuget.org/packages/TrayIcon/)
[![](https://img.shields.io/nuget/dt/TrayIcon)](https://www.nuget.org/packages/TrayIcon/)# Tray Icon
Library that allows use Tray Icon in WPF Application.
Ported from Windows Forms. Has wrapper for WPF ContexMenu (which converts it to Windows Forms ContextMenu). This is needed for good performance, and compatibility.
This library targets all MVVM requirements:
- it has bindable properties
- it has interface with notify methods## Getting started.
Use one of the follwing methods to install and use this library:- **Package Manager:**
```batch
PM> Install-Package TrayIcon
```- **.NET CLI:**
```batch
> dotnet add package TrayIcon
```
----
First you need to include namespace to your code or markup.For XAML it can look like:
```XAML```
And for C#:
```C#
using NullSoftware.ToolKit;
```
----
Then you can place tray icon inside your window, or keep it in variable/property.For XAML:
```XAML
```
For C#:
```C#
TrayIcon myTrayIcon = new TrayIcon()
{
Title = "My Application",
IconSource = new BitmapImage(new Uri("pack://application:,,,/MainIcon.ico")),
ClickCommand = new RelayCommand(ExampleAction)
};
```
----
To show balloon you need to call `Notify` method:
```C#
INotificationService notifyService = myTrayIcon;
notifyService.Notify("Greetings", "Hello World!", NotificationType.Information);
```
**Note:** `INotificationService` can be obtained from XAML by using `NotificationServiceMemberPath`.
It injects `INotificationService` to specified DataContext property.### Backward compatibility
To support latest .NET versions was added `ContextMenuVariation` property to `TrayIcon`.\
It allows to switch beetwen `System.Windows.Forms.ContextMenu` or `System.Windows.Forms.ContextMenuStrip`.\
**Warning:** .NET Core 3.1 and later versions don't support `System.Windows.Forms.ContextMenu`.
See more at the [documentation page](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.contextmenu).## Full Example
```XAML
```
ViewModel:
```C#
using System;
using System.Windows.Input;
using NullSoftware.ToolKit;
using PropertyChanged;public class MainViewModel : ObservableObject
{
public bool IsSilentModeEnabled { get; set; }[DoNotNotify]
public ICommand MinimazeCommand { get; }[DoNotNotify]
public ICommand SayHelloCommand { get; }[DoNotNotify]
public ICommand CloseCommand { get; }
[DoNotNotify]
private INotificationService NotificationService { get; set; }public MainViewModel()
{
MinimazeCommand = new RelayCommand(() => App.Current.MainWindow.WindowState = System.Windows.WindowState.Minimized);
SayHelloCommand = new RelayCommand(() => NotificationService.Notify("Greetings", "Hello World!"));
CloseCommand = new RelayCommand(App.Current.MainWindow.Close);
}
}
```
**Note:** in ViewModel was used [PropertyChanged.Fody](https://github.com/Fody/PropertyChanged) plugin, to simplify usage of `INotifyPropertyChanged`.