📌  相关文章
📜  如何为一个 ViewModel 使用多个命令 - C# 代码示例

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

代码示例3
public class RelayCommand : ICommand
{
    private readonly Predicate _canExecute;
    private readonly Action _execute;

    public RelayCommand(Predicate canExecute, Action execute)
    {
        this._canExecute = canExecute;
        this._execute = execute;
    }

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

    public bool CanExecute(object parameter)
    {
        return _canExecute(parameter);
    }

    public void Execute(object parameter)
    {
        _execute(parameter);
    }
}