Hello_Mac
that adds a single button and label to the main window. When the button is clicked, the label will display the number of times it has been clicked.Hello_Mac
for the App Name, and keep everything else as default. Click Next:Main
class contains the very first method that is run.AppDelegate
class that is responsible for listening to events from the operating system.Main
method which creates a new Xamarin.Mac app instance and passes the name of the class that will handle OS events, which in this case is the AppDelegate
class:AppDelegate.cs
file contains an AppDelegate
class, which is responsible for creating windows and listening to OS events:DidFinishLaunching
method runs after the app has been instantiated, and it’s responsible for actually creating the app's window and beginning the process of displaying the view in it.WillTerminate
method will be called when the user or the system has instantiated a shutdown of the app. The developer should use this method to finalize the app before it quits (such as saving user preferences or window size and location).ViewController
declaration represents the object that controls the actual app window. Generally, for every window created (and for many other things within windows), there is a controller, which is responsible for the window’s lifecycle, such as showing it, adding new views (controls) to it, etc.ViewController
class is the main window’s controller. The controller is responsible for the life cycle of the main window. This will be examined in detail later, for now take a quick look at it:Info.plist
file contains information about the Xamarin.Mac app such as its Name and Bundle Identifier:Main
in the dropdown relates to the Main.storyboard
in the project's source tree in the Solution Explorer. It also defines the app's icons by specifying the Asset Catalog that contains them (AppIcon in this case).Entitlements.plist
file controls entitlements that the Xamarin.Mac app has such as Sandboxing and iCloud:Main.storyboard
file in the Solution Explorer to open it for editing in Xcode and Interface Builder:.storyboard
files in this list such as Main.storyboard
.ViewController.h
as part of the shim Xcode Project it generated to use Interface Builder:.h
file mirrors the ViewController.designer.cs
that is automatically added to a Xamarin.Mac project when a new NSWindow
is created. This file will be used to synchronize the changes made by Interface Builder and is where the Outlets and Actions are created so that UI elements are exposed to C# code.ViewController.h
file:@interface ViewController : NSViewController {}
code:ClickedLabel
for the Name:@property (assign) IBOutlet NSTextField *ClickedLabel;
code:ClickedButton
as the Name:ViewController.h
file in Xcode:ViewController.cs
file for editing by double-clicking it in the Solution Explorer:ViewController
class to track the number of clicks that have happened. Edit the class definition and make it look like the following:ViewController
), override the ViewDidLoad
method and add some code to set the initial message for the label:ViewDidLoad
, instead of another method such as Initialize
, because ViewDidLoad
is called after the OShas loaded and instantiated the user interface from the .storyboard file. If the developer tried to access the label control before the .storyboard file has been fully loaded and instantiated, they would get a NullReferenceException
error because the label control would not exist yet.ViewController
class: