25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

ViewModelCommand.cs 1.2 KiB

8 ay önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Input;
  7. namespace Example.ViewModels
  8. {
  9. public class ViewModelCommand : ICommand
  10. {
  11. //Fields
  12. private readonly Action<object> _executeAction;
  13. private readonly Predicate<object> _canExecuteAction;
  14. public ViewModelCommand(Action<object> executeAction)
  15. {
  16. _executeAction = executeAction;
  17. _canExecuteAction = null;
  18. }
  19. public ViewModelCommand(Action<object> executeAction, Predicate<object> canExecuteAction)
  20. {
  21. _executeAction = executeAction;
  22. _canExecuteAction = canExecuteAction;
  23. }
  24. public event EventHandler CanExecuteChanged
  25. {
  26. add { CommandManager.RequerySuggested += value; }
  27. remove { CommandManager.RequerySuggested -= value; }
  28. }
  29. //Methods
  30. public bool CanExecute(object parameter)
  31. {
  32. return _canExecuteAction == null ? true : _canExecuteAction(parameter);
  33. }
  34. public void Execute(object parameter)
  35. {
  36. _executeAction(parameter);
  37. }
  38. }
  39. }