50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
|
|
namespace WpfViewModelFirst
|
|
{
|
|
public class CustomCommand : ICommand
|
|
{
|
|
private readonly Action<object?> _execute;
|
|
private readonly Predicate<object?>? _canExecute;
|
|
|
|
public CustomCommand(Action<object?> execute, Predicate<object?> canExecute)
|
|
{
|
|
_execute = execute;
|
|
_canExecute = canExecute;
|
|
}
|
|
|
|
public CustomCommand(Action<object?> execute)
|
|
{
|
|
_execute = execute;
|
|
}
|
|
|
|
public bool CanExecute(object? parameter)
|
|
{
|
|
return _canExecute == null || _canExecute(parameter);
|
|
}
|
|
|
|
public event EventHandler? CanExecuteChanged
|
|
{
|
|
add
|
|
{
|
|
CommandManager.RequerySuggested += value;
|
|
}
|
|
remove
|
|
{
|
|
CommandManager.RequerySuggested -= value;
|
|
}
|
|
}
|
|
|
|
public void Execute(object? parameter)
|
|
{
|
|
_execute(parameter);
|
|
}
|
|
|
|
}
|
|
}
|