Cosmos/source/Cosmos.Build.Builder/ViewModels/RelayCommand.cs
2018-03-27 22:36:18 +01:00

24 lines
755 B
C#

using System;
using System.Windows.Input;
namespace Cosmos.Build.Builder.ViewModels
{
internal class RelayCommand : ICommand
{
public event EventHandler CanExecuteChanged;
private Action<object> _execute;
private Func<object, bool> _canExecute;
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true;
public void Execute(object parameter) => _execute?.Invoke(parameter);
public void RaiseCanExecuteChanged(object sender, EventArgs e) => CanExecuteChanged?.Invoke(sender, e);
}
}