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.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
namespace MSSQL_MVVM_Sample.Structure
|
|
|
|
|
{
|
|
|
|
|
internal class DelegateCommand : ICommand
|
|
|
|
|
{
|
|
|
|
|
private readonly Action _execute;
|
|
|
|
|
private readonly Func<bool> _canExecute;
|
|
|
|
|
|
|
|
|
|
public event EventHandler? CanExecuteChanged;
|
|
|
|
|
|
|
|
|
|
public DelegateCommand(Action execute) : this(execute, null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DelegateCommand(Action execute, Func<bool> canExecute)
|
|
|
|
|
{
|
|
|
|
|
_execute = execute;
|
|
|
|
|
_canExecute = canExecute;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.CanExecuteChanged(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|