Faisal Ghaffar
Faisal Ghaffar

Reputation: 181

How to create and show menu when user right clicks on an NSTableCellView Xamarin.Mac

I need to show a menu on an NSTableView when user right clicks anywhere on the table row. Just like when we right click anywhere in the browser and menu shows up. enter image description here

Upvotes: 1

Views: 371

Answers (1)

SushiHangover
SushiHangover

Reputation: 74209

NSTableView has Menu property that can be assigned to your NSMenu.

Of course all this can be done in Xcode's IB, but if you are doing this programmatically you need to construct a NSMenu, add the NSMenuItem(s) required and assign it to the NSTableView.

var menu = new NSMenu("A context menu")
{
    Delegate = this
};
menu.AddItem(new NSMenuItem { Title = "StackOverflow" Action = SomeMenuAction });
aTableView.Menu = menu;

Upvotes: 1

Related Questions