Use custom NSApplication with Xamarin.Mac

How can i use my own derived NSApplication class with Xamarin.Mac? What i have so far is my custom NSApplication subclass

[Register("CustomNSApplication")]
public class CustomNSApplication : NSApplication
{
    public CustomNSApplication(IntPtr handle)
        :base(handle)
    {}

    public override void SendEvent(NSEvent theEvent)
    {
        // do nice stuff
        base.SendEvent(theEvent);
    }
}

According to the Apple documentation:

To use a custom subclass of NSApplication, simply send sharedApplication to your subclass rather than directly to NSApplication.

So my main method contains the following code:

        var appClassHandle = Class.GetHandle(typeof(CustomNSApplication));
        var selector = new Selector("sharedApplication");
        var nsappHandle = intptr_objc_msgSend(appClassHandle, selector.Handle);
        var customNSApplication = new CustomNSApplication(nsappHandle);

After this code the type of the NSApplication.SharedApplication is said to be CustomNSApplication which is what i would expect, but the method SendEvent never gets called.

Greetings Julius

Best Answer

Answers

Sign In or Register to comment.