diff options
Diffstat (limited to 'src/MVPtoMVVM.mvvm/viewmodels/SimpleCommand.cs')
| -rw-r--r-- | src/MVPtoMVVM.mvvm/viewmodels/SimpleCommand.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/MVPtoMVVM.mvvm/viewmodels/SimpleCommand.cs b/src/MVPtoMVVM.mvvm/viewmodels/SimpleCommand.cs new file mode 100644 index 0000000..904b000 --- /dev/null +++ b/src/MVPtoMVVM.mvvm/viewmodels/SimpleCommand.cs @@ -0,0 +1,38 @@ +using System;
+
+namespace MVPtoMVVM.mvvm.viewmodels
+{
+ public class SimpleCommand : IObservableCommand
+ {
+ private readonly Action command;
+ private Func<bool> predicate;
+
+ public SimpleCommand(Action command): this(command, () => true)
+ {
+
+ }
+
+ public SimpleCommand(Action command, Func<bool> predicate)
+ {
+ this.command = command;
+ this.predicate = predicate;
+ }
+
+ public void Execute(object parameter)
+ {
+ command();
+ }
+
+ public bool CanExecute(object parameter)
+ {
+ return predicate();
+ }
+
+ public void Changed()
+ {
+ CanExecuteChanged(this, EventArgs.Empty);
+ }
+
+ public event EventHandler CanExecuteChanged = (o,e)=>{};
+ }
+}
\ No newline at end of file |
