TrayIcon 1.0.7.2

.NET Core 3.0 .NET Framework 4.5
dotnet add package TrayIcon --version 1.0.7.2
NuGet\Install-Package TrayIcon -Version 1.0.7.2
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="TrayIcon" Version="1.0.7.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TrayIcon --version 1.0.7.2
#r "nuget: TrayIcon, 1.0.7.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install TrayIcon as a Cake Addin
#addin nuget:?package=TrayIcon&version=1.0.7.2

// Install TrayIcon as a Cake Tool
#tool nuget:?package=TrayIcon&version=1.0.7.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

Patch details (1.0.7.*)

  • Added events integration.
  • Fixed ClickCommand and DoubleClickCommand behaviors.
  • Small improvements.

Getting started.

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.


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>

continue reading →

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Framework net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.5.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.

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.0.7.2 5,059 3/12/2022
1.0.7.1 229 3/11/2022
1.0.7 232 3/11/2022
1.0.7-preview 80 3/11/2022
1.0.6.2 238 3/9/2022
1.0.6 232 3/9/2022
1.0.5.2 228 3/9/2022
1.0.5 231 3/9/2022
1.0.4.2 209 11/18/2021
1.0.4 183 11/18/2021
1.0.3 197 10/6/2021
1.0.2 267 10/3/2021
1.0.1 279 10/3/2021
1.0.0 354 10/3/2021

Added missed documentation.