Files
FSI.BT.IR.Tools/FSI.Lib/MVVM/DelegateCommand.cs
maier_S a0095a0516 Squashed 'FSI.Lib/' content from commit 6aa4846
git-subtree-dir: FSI.Lib
git-subtree-split: 6aa48465a834a7bfdd9cbeae8d2e4f769d0c0ff8
2022-03-23 10:15:26 +01:00

44 lines
1.0 KiB
C#

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
}
}