📜  RelayCommand - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:11.135000             🧑  作者: Mango

代码示例1
public class RelayCommand : ICommand
{
    private Action execute;
    private Func canExecute;

    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    }

    public RelayCommand(Action execute, Func canExecute)
    {
        this.execute = execute;
        this.canExecute = canExecute;
    }

    public bool CanExecute(object parameter)
    {
        return this.canExecute == null || this.canExecute(parameter);
    }

    public void Execute(object parameter)
    {
        this.execute(parameter);
    }
}