Karel_cz
Karel_cz

Reputation: 133

Xamarin - XAML - top bar app menu

I am working on Xamarin Mac app with XAML, but I am not able to add app menu to top bar. I think, that it is generated with xCode in Main.storyboard, but I am not using xCode, because of using XAML.

Upvotes: 2

Views: 627

Answers (1)

Karel_cz
Karel_cz

Reputation: 133

Found solution. I post it here for someone who can use it.

For adding menu item for quit app (in AppDelegate.cs):

// 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}", "appname");
var quitMenuItem = new NSMenuItem(quitTitle, "q", delegate {
    NSApplication.SharedApplication.Terminate(menubar);
});
appMenu.AddItem(quitMenuItem);

// finally add menu
NSApplication.SharedApplication.MainMenu = menubar;

Upvotes: 1

Related Questions