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