You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Common.cs 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.ComponentModel;
  2. using System;
  3. using System.Windows.Input;
  4. namespace starter.viewmodel.common
  5. {
  6. public abstract class NotificationObject : INotifyPropertyChanged
  7. {
  8. public event PropertyChangedEventHandler PropertyChanged;
  9. ///< summary>
  10. /// announce notification
  11. /// </summary>
  12. ///< param name="propertyName">property name</param>
  13. public void RaisePropertyChanged(string propertyName)
  14. {
  15. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  16. }
  17. }
  18. ///< summary>
  19. /// BaseCommand
  20. /// </summary>
  21. public class BaseCommand : ICommand
  22. {
  23. private Func<object, bool> _canExecute;
  24. private Action<object> _execute;
  25. public BaseCommand(Func<object, bool> canExecute, Action<object> execute)
  26. {
  27. _canExecute = canExecute;
  28. _execute = execute;
  29. }
  30. public BaseCommand(Action<object> execute) :
  31. this(null, execute)
  32. {
  33. }
  34. public event EventHandler CanExecuteChanged
  35. {
  36. add
  37. {
  38. if (_canExecute != null)
  39. {
  40. CommandManager.RequerySuggested += value;
  41. }
  42. }
  43. remove
  44. {
  45. if (_canExecute != null)
  46. {
  47. CommandManager.RequerySuggested -= value;
  48. }
  49. }
  50. }
  51. public bool CanExecute(object parameter)
  52. {
  53. return _canExecute == null ? true : _canExecute(parameter);
  54. }
  55. public void Execute(object parameter)
  56. {
  57. if (_execute != null && CanExecute(parameter))
  58. {
  59. _execute(parameter);
  60. }
  61. }
  62. }
  63. }