Replies: 3 comments 1 reply
-
Left click currently executes Clicked event. |
Beta Was this translation helpful? Give feedback.
-
@maxkatz6 This should be resolved better way. Perhaps, for example, the TrayIcon could have a ShowMenu function? Currently, on Windows, to display the menu in response to a left-click, I had to search the application's window list and send WM_USER message to the window handling the tray. Which is not an elegant solution ... |
Beta Was this translation helpful? Give feedback.
-
Here's a Window's only solution I found to show the menu on a left click. private void OnTrayIconClicked (object? sender, EventArgs e) {
// Get this tray icon's implementation
ITrayIconImpl? impl = (ITrayIconImpl?)GetType ()
.GetProperty ("Impl", BindingFlags.NonPublic | BindingFlags.Instance)?
.GetValue (this);
// Get the Windows tray icon implementation type
Type? type = AppDomain.CurrentDomain.GetAssemblies ()
.Where (a => a.FullName?.StartsWith ("Avalonia.Win32") ?? false)
.SelectMany (a => a.GetTypes ())
.FirstOrDefault (t => t.Name == "TrayIconImpl");
// If the Implementation and type are not null
if (impl != null && type != null) {
// Get the OnRightClicked method
MethodInfo? methodInfo = type.GetMethod ("OnRightClicked",
BindingFlags.NonPublic | BindingFlags.Instance);
// Invoke the method on the implementation
methodInfo?.Invoke (impl, null);
}
} |
Beta Was this translation helpful? Give feedback.
-
The default behaviour of TrayIcon to show NativeMenu is right click on it, but right click is more difficult than left click on touchable screen.
We can add Clicked event to TrayIcon, but i found no way to open NatvieMenu programmatically in it.
Does anyone know of any other solution?
Beta Was this translation helpful? Give feedback.
All reactions