Multiple Views that have same ViewModel

走远了吗. 提交于 2021-02-10 20:22:47

问题


In my Application business i have 3 step to define a person...in each step i get some info fro my person... For example i get firstname and lastname in step 1 and persontype in step 2 and get other info in step 3...

I use from transition UI for show steps to my user and using from Fluidkit

for any steps i have a usercontrol ...how can i bind my usercontrols to one ViewModel?


回答1:


Your question isn't very clear, but yes, you can certainly use the same ViewModel instance for multiple different views.

However, you can also keep your data in a model object, and have your ViewModels just be thin wrappers on top of it. So you could, for example, have a Person object, and have a PersonWizardStepOneViewModel with properties that read values from the Person and write values back to the Person (with any appropriate viewmodel logic added, e.g. enabling/disabling buttons based on other selections that have been made, etc.), a PersonWizardStepTwoViewModel, etc., and pass the Person along instead of sharing the same ViewModel.

It's up to you which way to do it. If the logic doesn't get too complicated and the viewmodel class doesn't get too large, using a single ViewModel instance is probably fine. If the viewmodel starts getting too large to work with comfortably, split it up.



来源:https://stackoverflow.com/questions/7010602/multiple-views-that-have-same-viewmodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!