38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
|
|
namespace _20230724_MBJC_upperpc.Common
|
|
{
|
|
public class RelayCommand : ICommand
|
|
{
|
|
private readonly Action<object> execute;
|
|
private readonly Func<object, bool> canExecute;
|
|
|
|
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
|
|
{
|
|
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
|
this.canExecute = canExecute;
|
|
}
|
|
|
|
public event EventHandler CanExecuteChanged
|
|
{
|
|
add { CommandManager.RequerySuggested += value; }
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|
}
|
|
|
|
public bool CanExecute(object parameter)
|
|
{
|
|
return canExecute == null || canExecute(parameter);
|
|
}
|
|
|
|
public void Execute(object parameter)
|
|
{
|
|
execute(parameter);
|
|
}
|
|
}
|
|
}
|