MVVMGroup.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. namespace IFramework.MVVM
  2. {
  3. /// <summary>
  4. /// MVVM 组结构
  5. /// </summary>
  6. public class MVVMGroup : Unit
  7. {
  8. private ViewModel _viewModel;
  9. private View _view;
  10. private IModel _model;
  11. private string _name;
  12. /// <summary>
  13. /// 组名
  14. /// </summary>
  15. public string name { get { return _name; } }
  16. /// <summary>
  17. /// 界面
  18. /// </summary>
  19. public View view { get { return _view; } }
  20. /// <summary>
  21. /// 数据
  22. /// </summary>
  23. public IModel model
  24. {
  25. get { return _model; }
  26. }
  27. /// <summary>
  28. /// VM
  29. /// </summary>
  30. public ViewModel viewModel
  31. {
  32. get { return _viewModel; }
  33. }
  34. /// <summary>
  35. /// Ctor
  36. /// </summary>
  37. /// <param name="name"></param>
  38. /// <param name="view"></param>
  39. /// <param name="viewModel"></param>
  40. /// <param name="model"></param>
  41. public MVVMGroup(string name, View view, ViewModel viewModel, IModel model)
  42. {
  43. this._name = name;
  44. this._view = view;
  45. this._model = model;
  46. this._viewModel = viewModel;
  47. this._viewModel.group = this;
  48. (_viewModel as IViewModel).Initialize();
  49. this._view.context = _viewModel;
  50. (_viewModel as IViewModel).SyncModelValue();
  51. }
  52. /// <summary>
  53. /// 发布model数据发生变化
  54. /// </summary>
  55. public void PublishModelDirty()
  56. {
  57. if (viewModel != null)
  58. {
  59. (_viewModel as IViewModel).SyncModelValue();
  60. }
  61. }
  62. /// <summary>
  63. /// 释放时
  64. /// </summary>
  65. public override void Dispose()
  66. {
  67. if (disposed) return;
  68. base.Dispose();
  69. if (_view != null)
  70. {
  71. _view.Dispose();
  72. }
  73. if (_viewModel != null)
  74. {
  75. _viewModel.Dispose();
  76. }
  77. }
  78. /// <summary>
  79. /// 释放时
  80. /// </summary>
  81. protected override void OnDispose() { }
  82. }
  83. }