You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
965 B
41 lines
965 B
using System; |
|
|
|
namespace ArducopterConfigurator.PresentationModels |
|
{ |
|
public interface ICommand |
|
{ |
|
void Execute(object parameter); |
|
bool CanExecute(object parameter); |
|
} |
|
|
|
public class DelegateCommand : ICommand |
|
{ |
|
private readonly Predicate<object> _canExecute; |
|
private readonly Action<object> _execute; |
|
|
|
public DelegateCommand(Action<object> execute) |
|
: this(execute, null) |
|
{ |
|
} |
|
|
|
public DelegateCommand(Action<object> execute, Predicate<object> canExecute) |
|
{ |
|
_execute = execute; |
|
_canExecute = canExecute; |
|
} |
|
|
|
public bool CanExecute(object parameter) |
|
{ |
|
if (_canExecute == null) |
|
return true; |
|
|
|
return _canExecute(parameter); |
|
} |
|
|
|
public void Execute(object parameter) |
|
{ |
|
_execute(parameter); |
|
} |
|
|
|
} |
|
} |