diff options
| author | Roy <roy.mail.net@gmail.com> | 2017-12-06 10:11:45 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2017-12-06 10:11:45 +0200 |
| commit | 3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e (patch) | |
| tree | def622f54dff1dfc0820ed8fdd96edad98c05ec3 /Software/Visual_Studio/Tango.Core/Commands | |
| parent | 3689238cb9ca77cbd7fa34dbd15003af87266e36 (diff) | |
| download | Tango-3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e.tar.gz Tango-3e665934f3f01b2cdd3de3fbc2c03ae27ac5740e.zip | |
Moved ExtendedObject & RelayCommand to Core.
CodeGeneration EntityCodeFile working + cycle reference!
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/Commands')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs b/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs new file mode 100644 index 000000000..f57a8699f --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace Tango.Core.Commands +{ + /// <summary> + /// RelayCommand is a very easy-to-use implementation of ICommand. You can use a RelayCommand to expose viewmodel functionality as a command, and + /// supply the condition that determines the command's availability. A control in the view bound to a command can execute an available command will</summary> + /// update its enabled state in response to the availability of the command. + /// <seealso cref="System.Windows.Input.ICommand" /> + public sealed class RelayCommand : ICommand + { + #region fields + readonly Predicate<object> canExecute; + readonly Action<object> execute; + #endregion fields + + #region constructors + public RelayCommand(Action<object> execute) : this(execute, null) { } + + public RelayCommand(Action<object> execute, Predicate<object> canExecute) + { + this.execute = execute; + this.canExecute = canExecute; + } + + public RelayCommand(Action execute) + : this((x) => execute()) + { + + } + + public RelayCommand(Action execute, Predicate<object> canExecute) + : this((x) => execute(), canExecute) + { + + } + + #endregion constructors + + #region methods + public void RaiseCanExecuteChanged() + { + if (this.CanExecuteChanged != null) + { + this.CanExecuteChanged(this, EventArgs.Empty); + } + } + #endregion methods + + #region ICommand events + public event EventHandler CanExecuteChanged; + #endregion ICommand events + + #region ICommand methods + public bool CanExecute(object parameter) + { + return this.canExecute != null ? this.canExecute(parameter) : true; + } + + public void Execute(object parameter) + { + if (this.execute != null) + { + this.execute(parameter); + } + } + #endregion ICommand methods + } + + public sealed class RelayCommand<T> : ICommand + { + #region fields + readonly Predicate<object> canExecute; + readonly Action<T> execute; + #endregion fields + + #region constructors + + public RelayCommand(Action<T> execute) : this(execute, null) { } + + public RelayCommand(Action<T> execute, Predicate<object> canExecute) + { + this.execute = execute; + this.canExecute = canExecute; + } + + public RelayCommand(Action execute) + : this((x) => execute()) + { + + } + #endregion constructors + + #region methods + public void RaiseCanExecuteChanged() + { + if (this.CanExecuteChanged != null) + { + this.CanExecuteChanged(this, EventArgs.Empty); + } + } + #endregion methods + + #region ICommand events + public event EventHandler CanExecuteChanged; + #endregion ICommand events + + #region ICommand methods + public bool CanExecute(object parameter) + { + return this.canExecute != null ? this.canExecute(parameter) : true; + } + + public void Execute(object parameter) + { + if (this.execute != null) + { + this.execute((T)parameter); + } + } + #endregion ICommand methods + } +} |
