blob: 4fde65f5d3c7de11d8a331f284a4f96ea503bbdf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
using System;
using System.Windows.Input;
using AppKit;
namespace Xamarin.PropertyEditing.Mac
{
internal class CommandButton : NSButton
{
private ICommand command;
public ICommand Command
{
get { return this.command; }
set {
if (this.command != null)
this.command.CanExecuteChanged -= CanExecuteChanged;
this.command = value;
if (this.command != null)
this.command.CanExecuteChanged += CanExecuteChanged;
}
}
public CommandButton ()
{
Activated += (object sender, EventArgs e) => {
var button = (CommandButton)sender;
button.command?.Execute (null);
};
}
private void CanExecuteChanged (object sender, EventArgs e)
{
if (sender is ICommand cmd)
this.Enabled = cmd.CanExecute (null);
}
}
}
|