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.

47 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace MVVMDatabaseSample.ViewModel
{
internal class DelegateCommand : ICommand
{
private readonly Func<bool> _canExecute;
private readonly Action _execute;
public event EventHandler? CanExecuteChanged;
public DelegateCommand(Action execute, Func<bool> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
public DelegateCommand(Action execute) : this(execute, null)
{
}
public bool CanExecute(object? parameter)
{
if (_canExecute == null)
return true;
return _canExecute();
}
public void Execute(object? parameter)
{
_execute();
}
public void RaiseCanExecuteChanged()
{
if (this.CanExecuteChanged != null)
this.CanExecuteChanged(this, EventArgs.Empty);
}
}
}