ViewModel.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace vCloud.GeneratePackages.Tool.ViewModels
  5. {
  6. public abstract class ViewModel : NotificationObject
  7. {
  8. private string _description;
  9. private bool _isVisible = true;
  10. private bool _isEnable = true;
  11. private bool _isDisposed;
  12. /// <summary>
  13. /// Description, display on UI
  14. /// </summary>
  15. public string Description
  16. {
  17. get { return _description; }
  18. set
  19. {
  20. if (_description != value)
  21. {
  22. _description = value;
  23. OnPropertyChanged(() => Description);
  24. }
  25. }
  26. }
  27. /// <summary>
  28. /// A Flag indicates this UI is visible
  29. /// </summary>
  30. public bool IsVisible
  31. {
  32. get { return _isVisible; }
  33. set
  34. {
  35. if (_isVisible != value)
  36. {
  37. _isVisible = value;
  38. OnPropertyChanged(() => IsVisible);
  39. }
  40. }
  41. }
  42. /// <summary>
  43. /// A Flag indicates this UI is enabled
  44. /// </summary>
  45. public bool IsEnabled
  46. {
  47. get { return _isEnable; }
  48. set
  49. {
  50. if (_isEnable != value)
  51. {
  52. _isEnable = value;
  53. OnIsEnabledChanged();
  54. OnPropertyChanged(() => IsEnabled);
  55. }
  56. }
  57. }
  58. protected virtual void OnIsEnabledChanged()
  59. {
  60. //TODO On IsEnabled changed, child class can override implement it
  61. }
  62. public void Dispose()
  63. {
  64. if (!_isDisposed)
  65. {
  66. DoDispose();
  67. _isDisposed = true;
  68. }
  69. }
  70. protected virtual void DoDispose()
  71. {
  72. //implement it in child class
  73. }
  74. }
  75. }