The easy to use and full featured Irc Bot everyone is talking about!
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.

ViewModelBase.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Interface.ViewModels
  8. {
  9. public class ViewModelBase : INotifyPropertyChanged
  10. {
  11. public event PropertyChangedEventHandler PropertyChanged;
  12. public void OnPropertyChanged(string propname)
  13. {
  14. if (PropertyChanged != null)
  15. {
  16. PropertyChanged(this, new PropertyChangedEventArgs(propname));
  17. }
  18. }
  19. public class DelegateCommand : System.Windows.Input.ICommand
  20. {
  21. private readonly Action _mExecute;
  22. private readonly Func<bool> _mCanExecute;
  23. public event EventHandler CanExecuteChanged;
  24. public DelegateCommand(Action execute)
  25. : this(execute, () => true) { /* empty */ }
  26. public DelegateCommand(Action execute, Func<bool> canexecute)
  27. {
  28. if (execute == null)
  29. throw new ArgumentNullException("execute");
  30. _mExecute = execute;
  31. _mCanExecute = canexecute;
  32. }
  33. public bool CanExecute(object p)
  34. {
  35. return _mCanExecute == null || _mCanExecute();
  36. }
  37. public void Execute(object p)
  38. {
  39. if (CanExecute(null))
  40. _mExecute();
  41. }
  42. public void RaiseCanExecuteChanged()
  43. {
  44. if (CanExecuteChanged != null)
  45. CanExecuteChanged(this, EventArgs.Empty);
  46. }
  47. }
  48. }
  49. }