TrayIcon.Menu: NativeMenu. Opening event is never invoked
See original GitHub issueDescribe the bug
I’m trying to create a tray icon menu with dynamic menu items. In order to refresh all items right before right-clicking the tray, I’m subscribing to the NeedsUpdate event of the NativeMenu that is assigned to the tray icon. However, that event is never invoked. Same issue with the Opening event; that isn’t raised either.
To Reproduce Steps to reproduce the behavior:
In my App.xaml I’ve declared a TrayIcon:
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon
Icon="/Resources/icon_white.ico"
ToolTipText="App"
Clicked="TrayIcon_OnClicked">
<TrayIcon.Menu>
<NativeMenu Items="{Binding MenuItems}"
NeedsUpdate="NativeMenu_OnNeedsUpdate"/>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>
In App.xaml.cs:
private void NativeMenu_OnNeedsUpdate(object? sender, EventArgs e)
{
Log.Debug("This line gets never called");
}
Expected behavior Invoke events properly when opening a tray icon menu
Desktop:
- OS: Arch Linux 5.15.36-1-lts (KDE)
- Version 0.10.13
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:9 (8 by maintainers)
Top Results From Across the Web
How to load an application to systemtray using Avalonia
I created a sample WPF application using .NET Framework (so that I was able to reference System.Windows.Forms ) and was able to have...
Read more >Touch001 Solving Tray Icon and minimalize UI problem on ...
When I started to think about features for my project it came to my mind, that when the user minimalizes the application it...
Read more >Adobe Flash Platform * Menu basics
Context menus: Context menus open in response to a right-click or command-click on an interactive object in SWF content or a document element...
Read more >TrayIcon (Java Platform SE 8 )
A TrayIcon can have a tooltip (text), an image, a popup menu, and a set of listeners associated with it ... TrayIcon processes...
Read more >TrayIcon
The TrayIcon control allows an Avalonia application to display an icon and a native menu in the system tray. It is supported on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Indeed, looks like
Opening-event is never called. However, I found a way to make dynamic menus work. Here is a draft that for sure needs some more love (null-checks, initial population etc.)My App.axaml looks like this:
And inside a Button-click I do this:
It’s a xml doc: https://github.com/AvaloniaUI/Avalonia/blob/2c7ae3a50fdbf7878f8dadc72fc5ddf5b24cd546/src/Avalonia.Controls/NativeMenu.cs#L23