OneCore.Net.WPF.SystemTray 1.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package OneCore.Net.WPF.SystemTray --version 1.0.1
                    
NuGet\Install-Package OneCore.Net.WPF.SystemTray -Version 1.0.1
                    
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="OneCore.Net.WPF.SystemTray" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OneCore.Net.WPF.SystemTray" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="OneCore.Net.WPF.SystemTray" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OneCore.Net.WPF.SystemTray --version 1.0.1
                    
#r "nuget: OneCore.Net.WPF.SystemTray, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OneCore.Net.WPF.SystemTray@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OneCore.Net.WPF.SystemTray&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=OneCore.Net.WPF.SystemTray&version=1.0.1
                    
Install as a Cake Tool

OneCore

OneCore.Net.WPF.SystemTray Library

Overview

OneCore.Net.WPF.SystemTray is a library that provides all the necessary tools to create and manage custom, styled system tray icons in WPF applications.

Preview

  • Unstyled with Native WPF
    Default
  • Styled with a light and dark theming
    Light Dark
  • Special Features
    Options

Features

  • Tray icon management: Have a tray icon for a owner window.
  • Context menu customization: Create, extend and style the context menu shown on the tray icon same ways as for any WPF control.
  • Event handling: Have access to the tray icon and its context menu by usual bindings on commands, or direct clicks.
  • Minimize to tray: Allows to configure the owner window to disappear from the task bar when minimized
  • ToolTips: Allows to set and update the tray icon tool tip at any time.
  • Open window on single or double click: Have a build in feature to bring the owner window back up by single or double click
  • Icon: Define the tray icon itself by giving a relative URL to an image or even application.
  • Hide if window shown: Build in special feature to show the tray icon only if the window is minimized.
  • Notifications: Show a windows notification, or so called baloon tip, on an easy way.

Getting Started

  1. Installation:

    • Install the OneCore.Net.WPF.SystemTray library via NuGet Package Manager:
    dotnet add package OneCore.Net.WPF.SystemTray
    
  2. Initialization A:

    • Initialize the system tray in your WPF application using XAML:
    <Window>
        <onecore:Tray.TrayIcon>
            <onecore:TrayIcon Icon="ApplicationName.exe" />
        </onecore:Tray.TrayIcon>
    </Window>
    
  3. Initialization B:

    • Initialize the system tray in your WPF application using C#
    public partial class MainWindow
    {
        private readonly TrayIcon _icon;
    
        public MainWindow()
        {
            InitializeComponent();
    
            _icon = new TrayIcon("ApplicationName.exe", this);
            _icon.Show();
        }
    }
    
  4. Context menu:

    • Use the WPF build in ContextMenu control to configure and style the context menu shown on the TrayIcon.
    <onecore:TrayIcon>
        <onecore:TrayIcon.ContextMenu>
            <ContextMenu>
                <onecore:ShowWindowMenuItem FontSize="{Binding FontSize}" FontWeight="Bold" Header="My Application" />
                <MenuItem Command="{Binding IncreaseFontCommand}" Header="Increase Font Settings" />
                <MenuItem Command="{Binding DecreaseFontCommand}" Header="Decrease Font Settings" />
                <Separator />
                <MenuItem Command="{Binding ShowNotificationCommand}" Header="Show Notification" />
                <Separator />
                <MenuItem Command="{Binding ShutdownCommand}" Header="Quit" />
            </ContextMenu>
        </onecore:TrayIcon.ContextMenu>
    </onecore:TrayIcon>
    
  5. Events / Commands:

    • Next to all what the MenuItem can; the tray icon itself has also commands and click callbacks available.
    <onecore:TrayIcon ClickCommand="{Binding SingleClickCommand}"
                      ClickCommandParameter="Single Click Parameter"
                      Click="OnSingleClick"
                      DoubleClickCommand="{Binding DoubleClickCommand}"
                      DoubleClickCommandParameter="Double Click Parameter"
                      DoubleClick="OnDoubleClick"/>
    
  6. Notifications:

    • When use bindings and XAML only, simply bind a notification data object and the notification will be shown on any change. Even when its the same data object reference.
    <onecore:Tray.TrayIcon>
        <onecore:TrayIcon Notification="{Binding Notification}" />
    </onecore:Tray.TrayIcon>
    
    public class MainViewModel : ObservableObject
    {
        private NotificationData _notification;
    
        public NotificationData Notification
        {
            get => _notification;
            private set => NotifyAndSetIfChanged(ref _notification, value);
        }
    
        public void ShowNotification()
        {
            Notification = new NotificationData("Caption", "Content", NotificationIcon.Info);
        }
    }
    
    • If the TrayIcon is accessible by C# code, the notification can be shown directly:
    public partial class MainWindow
    {
        private readonly TrayIcon _icon;
    
        private void ShowNotificationClick(object sender, RoutedEventArgs e)
        {
            _icon.ShowNotification(new NotificationData("Caption", "Content", NotificationIcon.Info));
        }
    }
    
  7. Extra features:

    • Most features are listed in this read me on top. But one more to mention is the build in MenuItem to bring the owner window back up from minimized state without any custom code needed.
    <onecore:TrayIcon>
        <onecore:TrayIcon.ContextMenu>
            <ContextMenu>
                <onecore:ShowWindowMenuItem FontSize="{Binding FontSize}" FontWeight="Bold" Header="My Application" />
            </ContextMenu>
        </onecore:TrayIcon.ContextMenu>
    </onecore:TrayIcon>
    

Example

  • XAML with Bindings
    <Window>
        <onecore:Tray.TrayIcon>
            <onecore:TrayIcon Icon="MyApplication.exe"
                              Notification="{Binding Notification}"
                              OpenWindowOnClick="True"
                              ToolTip="My Application">
                <onecore:TrayIcon.ContextMenu>
                    <ContextMenu>
                        <onecore:ShowWindowMenuItem FontSize="{Binding FontSize}" FontWeight="Bold" Header="My Application" />
                        <MenuItem Command="{Binding IncreaseFontCommand}" Header="Increase Font Settings" />
                        <MenuItem Command="{Binding DecreaseFontCommand}" Header="Decrease Font Settings" />
                        <Separator />
                        <MenuItem Command="{Binding ShowNotificationCommand}" Header="Show Notification" />
                        <Separator />
                        <MenuItem Command="{Binding ShutdownCommand}" Header="Quit" />
                    </ContextMenu>
                </onecore:TrayIcon.ContextMenu>
            </onecore:TrayIcon>
        </onecore:Tray.TrayIcon>
    </Window>
    
    public class MainViewModel : ObservableObject
    {
        private float _fontSize;
        private NotificationData _notification;
    
        public MainViewModel()
        {
            FontSize = 12;
            IncreaseFontCommand = new DelegateCommand(IncreaseFont);
            DecreaseFontCommand = new DelegateCommand(DecreaseFont);
            ShowNotificationCommand = new DelegateCommand(ShowNotification);
            ShutdownCommand = new DelegateCommand(Shutdown);
        }
    
        public float FontSize
        {
            get => _fontSize;
            private set => NotifyAndSetIfChanged(ref _fontSize, value);
        }
    
        public NotificationData Notification
        {
            get => _notification;
            private set => NotifyAndSetIfChanged(ref _notification, value);
        }
    
        public IDelegateCommand IncreaseFontCommand { get; }
        public IDelegateCommand DecreaseFontCommand { get; }
        public IDelegateCommand ShowNotificationCommand { get; }
        public IDelegateCommand ShutdownCommand { get; }
    
        private void IncreaseFont()
        {
            FontSize += 1;
        }
    
        private void DecreaseFont()
        {
            FontSize -= 1;
        }
    
        private void ShowNotification()
        {
            Notification = new NotificationData("Caption", "Content", NotificationIcon.Info);
        }
    
        private void Shutdown()
        {
            Environment.Exit(0); // Normally I would do that with the OneCore.WPF.Navigation.
        }
    }
    
  • C# with direct access
    public partial class MainWindow
    {
        private readonly TrayIcon _icon;
        private readonly MenuItem _mainContextMenuItem;
    
        public MainWindow()
        {
            InitializeComponent();
    
            _icon = new TrayIcon("SystemTray_NoPattern.exe", this)
            {
                ToolTip = "My Application",
                ContextMenu = new ContextMenu()
            };
            _icon.ContextMenu.Items.Add(new ShowWindowMenuItem { FontWeight = FontWeights.Bold, Header = "My Application" });
            _icon.ContextMenu.Items.Add(new MenuItem { Header = "Increase Font Settings" });
            _icon.ContextMenu.Items.Add(new MenuItem { Header = "Decrease Font Settings" });
            _icon.ContextMenu.Items.Add(new Separator());
            _icon.ContextMenu.Items.Add(new MenuItem { Header = "Show Notification" });
            _icon.ContextMenu.Items.Add(new Separator());
            _icon.ContextMenu.Items.Add(new MenuItem { Header = "Quit" });
    
            _mainContextMenuItem = (MenuItem)_icon.ContextMenu.Items[0];
            ((MenuItem)_icon.ContextMenu.Items[1]).Click += IncreaseFontClick;
            ((MenuItem)_icon.ContextMenu.Items[2]).Click += DecreaseFontClick;
            ((MenuItem)_icon.ContextMenu.Items[4]).Click += ShowNotificationClick;
            ((MenuItem)_icon.ContextMenu.Items[6]).Click += ShutdownClick;
    
            _icon.Show();
        }
    
        private void IncreaseFontClick(object sender, RoutedEventArgs e)
        {
            _mainContextMenuItem.FontSize += 1;
        }
    
        private void DecreaseFontClick(object sender, RoutedEventArgs e)
        {
            _mainContextMenuItem.FontSize -= 1;
        }
    
        private void ShowNotificationClick(object sender, RoutedEventArgs e)
        {
            _icon.ShowNotification(new NotificationData("Caption", "Content", NotificationIcon.Info));
        }
    
        private void ShutdownClick(object sender, RoutedEventArgs e)
        {
            _icon.Dispose();
            Close();
        }
    }
    

License

Copyright (c) David Wendland. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for full license information.

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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