Controllers in MVVM, How to get info from viewmodel to it's controller?

前端 未结 5 1420
时光取名叫无心
时光取名叫无心 2021-01-04 13:24

We are building an app using the MVVM pattern, we have controllers that wire up all the views and viewmodels using DI. All examples of MVVM I\'ve seen are really simplistic

5条回答
  •  死守一世寂寞
    2021-01-04 14:20

    Could your ViewModel not take a dependency on an IController or some other interface, so they can talk back to it? I try to keep as much application logic out of the ViewModel as possible, as these classes can easily become bloated.

     MyViewModel(IController controller)
     {
         this.controller = controller;
     }
    
     void Save()
     {
         this.controller.Save();
     }
    

    I do agree that the MVVM frameworks tend to be too simplistic with their samples. In particular, moving between views/screens in your application is something I would like to see more examples of. I create an IViewManager interface, to allow my ViewModels to request that we move to another view.

提交回复
热议问题