How to disable a UI control in Xamarin Mac (MonoMac)?

390 views Asked by At

Recently I've just started to learn using Xamarin and I made a tiny demo Mac app with Cocoa UI stuff for fun. Now I need to disable, and then re-enable a button on my app, I've search for a while and I've found this: How do I disable a UIButton?

But this article seems only works on iOS platform, there is no any references/methods on Xamarin.Mac. So I would like to know how to disable and enable the UI control on this platform.

Thanks and Regards, Jackson.

1

There are 1 answers

3
SushiHangover On BEST ANSWER

A NSButton as an Enabled property to enable/disable the control:

partial void EnableDisable(NSButton sender)
{
    EnableDisableBtn.Enabled = !EnableDisableBtn.Enabled;
}

Ref: https://developer.xamarin.com/api/property/MonoMac.AppKit.NSControl.Enabled/

Example:

var button = new NSButton(new CGRect(40, 40, 50, 40));
button.Enabled = true;
button.Activated += (object sender, EventArgs e) =>
{
    (sender as NSButton).Enabled = false;
};
View.AddSubview(button);