mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-03 21:25:13 +00:00
Double click events not being called after deleting tray icon and creating it again #899
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Arthurgroll997 on GitHub (Jun 21, 2023).
Specifications
Electron.NET CLI version: 23.6.1
Electron.NET API version: 23.6.1
.NET Core version: 6.0
Node.JS version: 18
Build target: Windows
Error description
I was trying to create a tray icon so that when the user closes the window it would be possible to show the window again by double clicking the tray icon.
I wanted to show the tray icon only when the window is hidden, so I would have to keep destroying and creating the tray icon again.
I noticed that the first time I closed the window the tray icon would work without any problems, but when I tried a second time it wouldn't work anymore.
The code I was using:
Steps to Reproduce:
Workaround for now
I actually found a workaroud for this (which I'm using right now), but it would be nice to have a permanent fix.
When analysing the code for the double click event, I noticed that it only registers the double click event when the _doubleClick event is null, and it does not make _doubleClick null again when the Destroy method is called.
The OnDoubleClick event code:
The Destroy code:
So I tried my luck using reflection and setting the _doubleClick property to null in the CloseWindow method, and as expected it worked as a charm.
Conclusion
So that is it.
I'm not entirely sure if this is happening to other events such as the click event, but it might aswell be happening to them, and it would be nice to check it out too