You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

2 years ago
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<string> _execute;
private Predicate<string> _canExecute;
public event EventHandler? CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public MessageCommand(Action<string> execute, Predicate<string> 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);
}
}
}