using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; namespace CommandSample.Commands { internal class MessageCommand : ICommand { private Action _execute; private Predicate _canExecute; public event EventHandler? CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public MessageCommand(Action execute, Predicate canExecute) { _execute = execute; _canExecute = canExecute; } public bool CanExecute(object? parameter) { bool result = _canExecute.Invoke(parameter as string); return result; } public void Execute(object? parameter) { if (_execute == null) return; _execute.Invoke(parameter as string); } } }