hardcodet / wpf-notifyicon

NotifyIcon (aka system tray icon or taskbar icon) for the WPF platform
MIT License
830 stars 130 forks source link

Does this support .NET 5.0? Application instantly closes on executing a command without exception or error #68

Closed JordanAnthonyKing closed 2 years ago

JordanAnthonyKing commented 2 years ago

Hi, I've been trying to use this library, I've duplicated the code in the Windowless Sample in my .NET 5.0 project, and although a tray icon is shown, and a menu can be accessed, the application will close without exception or error when attempting to execute any of the commands.

My project with is available at https://github.com/JordanAnthonyKing/KeyboardUsurper/tree/NotifyIconIssue

Lakritzator commented 2 years ago

Yes, 1.1.0 works fine with .NET 5.0 and your test project also works for me (after I fix it to work without a configuration) I see a disable, if I click it, I see an enable in the menu.

JordanAnthonyKing commented 2 years ago

Hi, judging by your comment it seems you have tested the master branch, not the NotifyIconIssue branch linked.

The master branch does work however using the classes in the System.Windows.Forms namespace results in a context menu that doesn't respect Windows' dpi settings. Using the Hardcodet.Wpf.TaskbarNotification namespace and classes as shown in the samples results in the issue described where interacting with the tray icon causes the application to exit without errors or exceptions.

Erapchu commented 2 years ago

@JordanAnthonyKing Hello, you need to set ShutdownMode="OnExplicitShutdown" in App.xaml

Erapchu commented 2 years ago

That behavior occurs because your application doesn't have any window on startup and default value is OnLastWindowClose. No windows creating during application start. Only popups on mouse over, when they are vanished, last "window" (popup) closed and your application will closing.

JordanAnthonyKing commented 2 years ago

Took a while to circle back to this, thanks again for the solution