Two views - one ViewModel

前端 未结 3 1482
孤独总比滥情好
孤独总比滥情好 2021-01-15 18:17

I must have misunderstood the concept of ViewModels and Views. But at this moment I can\'t rebuild the application from ground and this time doing it better. My

3条回答
  •  迷失自我
    2021-01-15 18:34

    You should ask yourself if both of your views should share the same viewmodel? Does they share the sameproperties in the view model or that they have different properties? If they should share the same viewmodel you should use locator create the viewmodel from the locator and pass the locator to the views. Otherwise, You should have two viewmodels. in order to keep minimal cuppling between the viewmodels you should use a service which known by both of the viewmodels (better via interfaces). One viewmodel notify the service about action that have been performed, and the second viewmodel has been handle that action (By register to event)

    Good Luck,

    M. Moshe

提交回复
热议问题