1

I have been working on an .NET MAUI app that needs to have a status bar icon and when clicked, menu to be shown. I know it is a platform specific issue and I have been folowing this tutorial from Microsoft. They have image button implemented to be shown in the status menu bar in the TrayService.

This runtime binding and creating objects are diffucult to me. The idea is to create NSMenu object, assign it to the NSStatusBar object, then create NSMenu Items with appropriate click events and assign them to the NSMenu object.

I am struggling since I don't know how to create the NSMenu object, and NSMenuItem objects with Title property for example.

NSMenu have many constructors, properties, methods to use and I don't know how to use them.

I will be very greatful with explanation or example on how to start.

_statusBarMenu = Runtime.GetNSObject(Class.GetHandle("NSMenu"));
IntPtr_objc_msgSend_String(_statusBarMenu.Handle, Selector.GetHandle("initWithTitle:"), "Quit");
void_objc_msgSend_IntPtr(_statusBarItem.Handle, Selector.GetHandle("setMenu:"), _statusBarMenu.Handle);

This compiles fine, but I don't know if IntPtr_objc_msgSend_String method exist because I added it myself at the top. However, nothing shows up in the tray.

1 Answers1

0

It should be noted that Mac Catalyst is used in Maui, NSMenu and NSMenuItem are in Macos, and are not supported in Maui. For the Mac Catalyst creation menu in Maui you can refer to:

Menubar

Adding Menus and Shortcuts to the Menu Bar and User Interface | Apple Developer

Zack
  • 1,255
  • 1
  • 2
  • 5
  • Hey, thanks for the answer. Can you provide some reference that NSMenu and NSMenuItem are not supported in maui? I know that they are not included in the framework but my question was how to achieve them using platform specific commands (obj c). Also, the Menubar that is supported is for the menu on the left and not for the tray. – DesmondMilez Jan 16 '23 at 12:52
  • About you want to implement menu on obj c, you can refer to the answer of thread ["For Objective-C, the nsmenuitem nsmenu menu bar does not display problems"](https://stackoverflow.com/questions/68507113/for-objective-c-the-nsmenuitem-nsmenu-menu-bar-does-not-display-problems) – Zack Jan 17 '23 at 06:15