TrayIcon 1.1.2
dotnet add package TrayIcon --version 1.1.2
NuGet\Install-Package TrayIcon -Version 1.1.2
<PackageReference Include="TrayIcon" Version="1.1.2" />
<PackageVersion Include="TrayIcon" Version="1.1.2" />
<PackageReference Include="TrayIcon" />
paket add TrayIcon --version 1.1.2
#r "nuget: TrayIcon, 1.1.2"
#:package TrayIcon@1.1.2
#addin nuget:?package=TrayIcon&version=1.1.2
#tool nuget:?package=TrayIcon&version=1.1.2
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:
PM> Install-Package TrayIcon.NET CLI:
> dotnet add package TrayIcon
First you need to include namespace to your code or markup.
For XAML it can look like:
<Window xmlns:icon="https://github.com/nullsoftware/TrayIcon" />
And for C#:
using NullSoftware.ToolKit;
Then you can place tray icon inside your window, or keep it in variable/property.
For XAML:
<icon:TrayIconHandlers.TrayIcons>
<icon:TrayIcon Title="My Application"
IconSource="MainIcon.ico"
ClickCommand="{Binding ExampleCommand}"
NotificationServiceMemberPath="NotificationService"/>
</icon:TrayIconHandlers.TrayIcons>
For 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:
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.
Full Example
<Window x:Class="TrayIcon.Example.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TrayIcon.Example"
xmlns:vm="clr-namespace:TrayIcon.Example.ViewModels"
xmlns:icon="https://github.com/nullsoftware/TrayIcon"
mc:Ignorable="d"
Title="MainWindow"
Height="450" Width="800"
Icon="MainIcon.ico">
<Window.DataContext>
<vm:MainViewModel/>
</Window.DataContext>
<icon:TrayIconHandlers.TrayIcons>
<icon:TrayIcon Title="My Application"
IconSource="MainIcon.ico"
DoubleClickCommand="{Binding MinimazeCommand}"
NotificationServiceMemberPath="NotificationService">
<icon:TrayIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Notify" Command="{Binding SayHelloCommand}" icon:TrayIcon.IsDefault="True"/>
<Separator/>
<MenuItem Header="_Silent Mode" IsCheckable="True" IsChecked="{Binding IsSilentModeEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Separator/>
<MenuItem Header="E_xit" Command="{Binding CloseCommand}"/>
</ContextMenu>
</icon:TrayIcon.ContextMenu>
</icon:TrayIcon>
</icon:TrayIconHandlers.TrayIcons>
<Grid>
<StackPanel VerticalAlignment="Top"
HorizontalAlignment="Left"
Margin="10, 20"
Orientation="Horizontal">
<CheckBox VerticalAlignment="Center"
IsChecked="{Binding IsSilentModeEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Content="Silent Mode"/>
<Button Margin="20, 0, 0, 0"
Padding="10, 3"
MinWidth="86"
Command="{Binding SayHelloCommand}"
Content="Notify"/>
</StackPanel>
</Grid>
</Window>
ViewModel:
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 plugin, to simplify usage of INotifyPropertyChanged.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Credits
Developed by Null Software
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net5.0-windows7.0 is compatible. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows7.0 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net7.0-windows7.0 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. net8.0-windows7.0 is compatible. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net9.0-windows7.0 is compatible. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net10.0-windows7.0 is compatible. |
| .NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
| .NET Framework | net452 is compatible. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 was computed. |
-
.NETCoreApp 3.0
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
net10.0-windows7.0
- No dependencies.
-
net5.0-windows7.0
- No dependencies.
-
net6.0-windows7.0
- No dependencies.
-
net7.0-windows7.0
- No dependencies.
-
net8.0-windows7.0
- No dependencies.
-
net9.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.1.2 | 0 | 2/15/2026 | |
| 1.1.1.1 | 3,290 | 3/13/2024 | |
| 1.1.0.2 | 679 | 2/11/2024 | |
| 1.1.0.1 | 251 | 2/10/2024 | |
| 1.1.0 | 284 | 2/10/2024 | |
| 1.0.7.2 | 18,778 | 3/12/2022 | |
| 1.0.7.1 | 566 | 3/11/2022 | |
| 1.0.7 | 575 | 3/11/2022 | |
| 1.0.7-preview | 413 | 3/11/2022 | |
| 1.0.6.2 | 598 | 3/9/2022 | |
| 1.0.6 | 574 | 3/9/2022 | |
| 1.0.5.2 | 567 | 3/9/2022 | |
| 1.0.5 | 575 | 3/9/2022 | |
| 1.0.4.2 | 449 | 11/18/2021 | |
| 1.0.4 | 435 | 11/18/2021 | |
| 1.0.3 | 441 | 10/6/2021 | |
| 1.0.2 | 502 | 10/3/2021 | |
| 1.0.1 | 549 | 10/3/2021 |
Fixed critical bug with checkable menu items