Paste
Pasted as C# by Anon ( 8 years ago )
using System;
using System.Windows.Input;
namespace AppSettingInterface.Commands
{
public class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public event EventHandler CanExecuteChanged;
public DelegateCommand( Action<object> execute, Predicate<object> canExecute )
{
_execute = execute;
_canExecute = canExecute;
}
public DelegateCommand( Action<object> execute ) : this( execute, null ) { }
public virtual bool CanExecute( object parameter )
{
if( _canExecute == null )
{
return true;
}
return _canExecute( parameter );
}
public void Execute( object parameter ) =>_execute( parameter );
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke( this, EventArgs.Empty );
}
}
Revise this Paste