Skip to content

Instantly share code, notes, and snippets.

@chamons
Created March 10, 2016 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/15ffc5c8c62386aea9d5 to your computer and use it in GitHub Desktop.
Save chamons/15ffc5c8c62386aea9d5 to your computer and use it in GitHub Desktop.
using System;
using AppKit;
using Foundation;
namespace TestMenu
{
public partial class ViewController : NSViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var menu = NSApplication.SharedApplication.Menu;
var menuDelegate = menu.Delegate;
if (menuDelegate == null)
{
MyMenuDelegate.Me = new MyMenuDelegate();
menu.Delegate = MyMenuDelegate.Me;
}
}
private class MyMenuDelegate : NSMenuDelegate
{
internal static MyMenuDelegate Me { get; set; }
#region implemented abstract members of NSMenuDelegate
public override void MenuWillHighlightItem(NSMenu menu, NSMenuItem item)
{
}
#endregion
public override bool HasKeyEquivalentForEvent(NSMenu menu, NSEvent theEvent, NSObject target, ObjCRuntime.Selector action)
{
return false;
}
}
public override NSObject RepresentedObject
{
get
{
return base.RepresentedObject;
}
set
{
base.RepresentedObject = value;
// Update the view, if already loaded.
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment