51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
|
|
namespace StammGenerator.ViewModel
|
|
{
|
|
[Serializable]
|
|
class RelayCommand : ICommand
|
|
{
|
|
#region Fields
|
|
private readonly Action<object> execute;
|
|
private readonly Predicate<object> canExecute;
|
|
#endregion
|
|
|
|
#region Constructors
|
|
public RelayCommand(Action<object> execute) : this(execute, null) { }
|
|
|
|
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
|
|
{
|
|
if (execute == null) throw new ArgumentNullException("execute");
|
|
this.execute = execute;
|
|
this.canExecute = canExecute;
|
|
}
|
|
#endregion
|
|
|
|
#region ICommand Members
|
|
[DebuggerStepThrough]
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
if (canExecute == null) return true;
|
|
return canExecute(parameter);
|
|
}
|
|
|
|
public event EventHandler CanExecuteChanged
|
|
{
|
|
add { CommandManager.RequerySuggested += value; }
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
}
|
|
|
|
public void Execute(object parameter)
|
|
{
|
|
execute(parameter);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|