Extensions.Hosting.Wpf.TrayIcon
3.1.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Extensions.Hosting.Wpf.TrayIcon --version 3.1.0
NuGet\Install-Package Extensions.Hosting.Wpf.TrayIcon -Version 3.1.0
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="Extensions.Hosting.Wpf.TrayIcon" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Extensions.Hosting.Wpf.TrayIcon --version 3.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Extensions.Hosting.Wpf.TrayIcon, 3.1.0"
#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.
// Install Extensions.Hosting.Wpf.TrayIcon as a Cake Addin #addin nuget:?package=Extensions.Hosting.Wpf.TrayIcon&version=3.1.0 // Install Extensions.Hosting.Wpf.TrayIcon as a Cake Tool #tool nuget:?package=Extensions.Hosting.Wpf.TrayIcon&version=3.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Microsoft.Extensions.Hosting.Wpf.TrayIcon
Extension library for Microsoft.Extensions.Hosting.Wpf
. This adds support to use tray icon with Microsoft.Extensions.Hosting.Wpf
.
Getting Started
Install nuget
Install-Package Extensions.Hosting.Wpf.TrayIcon
Register service
private static void ConfigureServices(HostBuilderContext hostContext, IServiceCollection services)
{
services.AddWpf<App>();
services.AddWpfTrayIcon<TrayIcon>(); //<--- new line
}
Example TrayIcon implementation
public class TrayIcon : ITrayIcon
{
private NotifyIcon? _notifyIcon;
private ContextMenuStrip? _contextMenu;
private ToolStripMenuItem? _exitItem;
private ToolStripMenuItem? _versionItem;
private IContainer? _components;
public IWpfThread WpfThread { get; }
public TrayIcon(IWpfThread wpfThread)
{
WpfThread = wpfThread;
}
public void InitializeComponent()
{
_components = new Container();
_contextMenu = new ContextMenuStrip();
_exitItem = new ToolStripMenuItem();
_versionItem = new ToolStripMenuItem();
//Initialize exitItem
_exitItem.Text = "E&xit";
_exitItem.Click += ExitItemOnClick;
//Initialize versionItem
_versionItem.Enabled = false;
_versionItem.Text = Application.ProductVersion;
// Initialize contextMenu
_contextMenu.Items.AddRange(new ToolStripItem[] { _versionItem, _exitItem });
// Create the NotifyIcon.
_notifyIcon = new NotifyIcon(_components);
// The Icon property sets the icon that will appear
// in the systray for this application.
_notifyIcon.Icon = Resources.Dog;
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
_notifyIcon.ContextMenuStrip = _contextMenu;
// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
_notifyIcon.Text = $@"{Application.ProductVersion}";
_notifyIcon.Visible = true;
}
private void ExitItemOnClick(object? sender, EventArgs e)
{
//Shutdown entire application in a proper way.
WpfThread.HandleApplicationExit();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_notifyIcon?.Dispose();
_versionItem?.Dispose();
_contextMenu?.Dispose();
_exitItem?.Dispose();
_components?.Dispose();
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Extensions.Hosting.Wpf (>= 3.1.0)
-
net6.0-windows7.0
- Extensions.Hosting.Wpf (>= 3.1.0)
-
net7.0-windows7.0
- Extensions.Hosting.Wpf (>= 3.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.