Reputation: 1995
I have a SourceList (NSOutlineView) and I want to display a context menu for some of the items. Looking around I have found answers in Cocoa and Obj-C but I am trying to do this in MonoMac and C#.
It seems to me I need to do my own custom class which inherits from NSOutlineView and implement the method MenuForEvent. But when I try to replace my old, standard NSOutlineView with my own custom class, nothing shows up during runtime. In my controller I call View.ReplaceSubviewWith(oldTree, newTree).
Do I need to do something else? Or perhaps there's another way to accomplish this?
Upvotes: 0
Views: 183
Reputation: 12566
Instead of trying to swap the instance like that, you should be able to do it declaratively.
Make sure you 'Register' your custom outline view, e.g.:
[Register("MySourceList")]
private class MySourceList : NSOutlineView
{
// Need this constructor for items created in .xib
public MySourceList(IntPtr handle) : base(handle)
{ }
Then, in the Xcode designer, select your outline view and specify the name you registered as the Custom Class for that object:
That way, when your view is created from the nib, the runtime will create the proper instance of your outline view in the first place.
Upvotes: 1