Forum Xamarin.Mac


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Use custom NSApplication with Xamarin.Mac

JuliusZintJuliusZint USMember ✭✭

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

public class CustomNSApplication : NSApplication
    public CustomNSApplication(IntPtr handle)

    public override void SendEvent(NSEvent theEvent)
        // do nice stuff

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


Sign In or Register to comment.