using System.Windows.Input; namespace SHH.CameraDashboard; // =========================================================================== // 1. 新增:非泛型 RelayCommand (支持 new RelayCommand(Method, Check)) // =========================================================================== public class RelayCommand : ICommand { private readonly Action _execute; private readonly Predicate _canExecute; public RelayCommand(Action execute, Predicate canExecute = null) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } public bool CanExecute(object parameter) { return _canExecute == null || _canExecute(parameter); } public void Execute(object parameter) { _execute(parameter); } public event EventHandler CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; } } // =========================================================================== // 2. 保留:泛型 RelayCommand (支持 new RelayCommand(Method...)) // =========================================================================== public class RelayCommand : ICommand { private readonly Action _execute; private readonly Predicate _canExecute; public RelayCommand(Action execute, Predicate canExecute = null) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } public bool CanExecute(object parameter) { return _canExecute == null || _canExecute((T)parameter); } public void Execute(object parameter) { _execute((T)parameter); } public event EventHandler CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; } }