|
using System;
using System.Windows.Input;
namespace OdsReadWrite
{
internal sealed class DelegateCommand : ICommand
{
private readonly Action execute;
private readonly Func<bool> canExecute;
public event EventHandler CanExecuteChanged;
public DelegateCommand(Action execute)
: this(execute, null)
{
}
public DelegateCommand(Action execute, Func<bool> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
this.execute = execute;
this.canExecute = canExecute;
}
public void InvalidateCanExecuteChanged()
{
var handler = this.CanExecuteChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
public void Execute(object parameter)
{
this.execute();
}
public bool CanExecute(object parameter)
{
return this.canExecute == null || this.canExecute();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.