'TrayIcon with WinUI 3
I am trying to make a program that runs in the background, and I want to place a Tray Icon in the Tray Icon Section of Windows.
I didn't find a solution to do this without using Windows Forms (which is not Possible in .Net 6)
Is there any other solution to display an Tray Icon or isn't it possible anymore?
Solution 1:[1]
Please take a look at this website:
https://stefanwick.com/2017/06/24/uwp-app-with-systray-extension
Solution 2:[2]
I know of two implementations of this in WinUI 3 in the form of ready-made NuGet libraries:
- Mine, based on the popular WPF library Hardcodet.NotifyIcon.Wpf - https://github.com/HavenDV/H.NotifyIcon/
Supports context menu. - Morten Nielsen implementation - https://github.com/dotMorten/WinUIEx/blob/main/docs/concepts/TrayIcon.md
Solution 3:[3]
It is possible but some if and buts are there. Also, you can get a System Tray Icon but some limitations such as:
- You cannot have
Context Menu
for your system tray (or may be you have to do some custom code). - You may experience
App Crash
when some specific controls are there in your window and you interact with them and then loose Focus from your app to another App. (This is the issue one has to fix in this sample POC).
This is the POC i've created for various purposes on WinUI3 which also includes your requirement.
Kindly mark this as an answer if it serves your purpose.
Thanks :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | FrozenAssassine |
Solution 2 | Konstantin S. |
Solution 3 | Mayur Paghdal |