Search code examples
c#xcodemonointerface-buildermonomac

Creating a simple Hello World app with MonoMac


I installed XCode, MonoMac, Mono and MonoDevelop on a Mac OS X machine, and I cant for the love of me figure out how to successfully wire up a Click event to a simple button.

First, I control-dragged my button to the header file, and it created an outlet. Now, I can access my button (btnHello) from C# code, thats cool - but how, and where, do I bind events to it?

I tried doing

this.btnHello.PerformClick += delegate {
    this.Title = "Hello World";
};

but MonoDevelop complains about I cant do that, due to some "method group" stuff.

I have been researching this for days, and I cant find any tutorials on how to do this, and I dont want to use sample code as it does not give me the process of how to do this properly in the future. I tried looking at the MonoTouch getting started guide, since it is close to MonoMac, but that did not help either.

Any help would be great, especially regarding outlets and actions, and how I can wire them up to my elements! Thank you!


Solution

  • Try:

        this.btnHello.Activated += delegate {
        this.Title = "Hello World";
    };
    

    This code should go somewhere in your Controller, most likely in AwakeFromNib.