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

前端 未结 5 1431
时光取名叫无心
时光取名叫无心 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:08

    I use a similar setup to you. In my controller, where my DI and view injection goes down, I sometimes keep reference to the ViewModel (which hold the View). Some cases I may have an event on the VM which is handled by the controller. In other, extreme cases (like if the VM/V was created outside the controller, say in another VM), I may even use the EventAggregator (with a strong ref) to listen to events that may be fired on the VM. In that case, a stored ref to the VM is not needed.

提交回复
热议问题