App using XAML - how to app menu

Hi, I am creating MacOS app using XAML, but I can not set app menu in top bar. App has only apple icon and app name, but I need to add there menu item for quit app and other links. I found solution for creating status menu, but it is not good way. Thanks for help.

Tagged:

Best Answer

  • karelsmetanakarelsmetana ✭✭
    Accepted Answer

    Solved. I found solution. Posting solution for adding menu item for quit from the app.

                // top bar app menu
                NSMenu menubar = new NSMenu();
                NSMenuItem appMenuItem = new NSMenuItem();
                menubar.AddItem(appMenuItem);
    
                NSMenu appMenu = new NSMenu();
    
                // add quit menu item
                string quitTitle = String.Format("Quit {0}", "some app name");
                var quitMenuItem = new NSMenuItem(quitTitle, "q", delegate {
                    NSApplication.SharedApplication.Terminate(menubar);
                });
                appMenu.AddItem(quitMenuItem);
    
                NSApplication.SharedApplication.MainMenu = menubar;
    

Answers

  • karelsmetanakarelsmetana Member ✭✭
    Accepted Answer

    Solved. I found solution. Posting solution for adding menu item for quit from the app.

                // top bar app menu
                NSMenu menubar = new NSMenu();
                NSMenuItem appMenuItem = new NSMenuItem();
                menubar.AddItem(appMenuItem);
    
                NSMenu appMenu = new NSMenu();
    
                // add quit menu item
                string quitTitle = String.Format("Quit {0}", "some app name");
                var quitMenuItem = new NSMenuItem(quitTitle, "q", delegate {
                    NSApplication.SharedApplication.Terminate(menubar);
                });
                appMenu.AddItem(quitMenuItem);
    
                NSApplication.SharedApplication.MainMenu = menubar;
    
Sign In or Register to comment.