RelayComand.cs 874 B

123456789101112131415161718192021222324252627282930313233343536
  1. // 事件传递类,用于传递界面的事件
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Input;
  8. namespace MvvmScaffoldFrame48.ViewModel.ViewModel
  9. {
  10. public class RelayCommand : ICommand
  11. {
  12. public event EventHandler CanExecuteChanged;
  13. private Action<object> _Excute { get; set; }
  14. private Predicate<object> _CanExcute { get; set; }
  15. public RelayCommand(Action<object> ExcuteMethod, Predicate<object> CanExcuteMethod)
  16. {
  17. _Excute = ExcuteMethod;
  18. _CanExcute = CanExcuteMethod;
  19. }
  20. public bool CanExecute(object parameter)
  21. {
  22. return _CanExcute(parameter);
  23. }
  24. public void Execute(object parameter)
  25. {
  26. _Excute(parameter);
  27. }
  28. }
  29. }