Squashed 'FSI.Lib/' content from commit dceb500
git-subtree-dir: FSI.Lib git-subtree-split: dceb5008a2176c2b8ab5e55a73b1c25d31a7f841
This commit is contained in:
43
FSI.Lib/MVVM/DelegateCommand.cs
Normal file
43
FSI.Lib/MVVM/DelegateCommand.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FSI.Lib.MVVM
|
||||
{
|
||||
/// <summary>
|
||||
/// DelegateCommand borrowed from
|
||||
/// http://www.wpftutorial.net/DelegateCommand.html
|
||||
/// </summary>
|
||||
public class DelegateCommand : ICommand
|
||||
{
|
||||
private readonly Predicate<object> _canExecute;
|
||||
private readonly Action<object> _execute;
|
||||
|
||||
public DelegateCommand(Action<object> execute,
|
||||
Predicate<object> canExecute = null)
|
||||
{
|
||||
_execute = execute;
|
||||
_canExecute = canExecute;
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region ICommand Members
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return _canExecute == null || _canExecute(parameter);
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute(parameter);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user