AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.23k stars 2.19k forks source link

TrayIcon: Baloon / Toast notification support #6734

Open FG-rgb opened 2 years ago

FG-rgb commented 2 years ago

Hello,

I want to use the new TrayIcon feature.

But I'm missing the possibility to show a balloon / toast notification.

I have the need for a balloon text, or a custom baaloon like in other UI frameworks E.g. https://docs.microsoft.com/de-de/dotnet/api/system.windows.forms.notifyicon.showballoontip?view=windowsdesktop-5.0 Or http://www.hardcodet.net/wpf-notifyicon/comment-page-5

With best regards.

Zilkode commented 2 years ago

@FG-rgb If i may suggest. I had thee same requirement as yours, i spent hours searching the best solution for Windows notification (toast). Although it's a Windows 10+ solution i find it partial solution for my purpose, until the awesome Avalonia contributors will work on this matter.

Long story short, if you are looking for Windows toast you can use the native UWP ToastContentBuilder Head to Send a local toast notification from C# apps for implementation tutorial.

There are a slight adjustments that need to be done though. In my case i split my platform dependent hookups to different projects, i.e Windows, Linux, Mac. Set your Windows project to target NetCore 3.1 or above. I add my platform specific packages to my Windows dependency (that way you can drop irrelevant assemblies per platform).

  1. add Nuget package Microsoft.Toolkit.Uwp.Notifications to your project.
  2. The following code is straight forward and ready to use for basic usage: new ToastContentBuilder() .AddArgument("action", "viewConversation") .AddArgument("conversationId", 9813) .AddText("Andrew sent you a picture") .AddText("Check this out, The Enchantments in Washington!") .Show();

Hope you find it useful.