具有相同 ViewModel 的多个视图
在我的应用程序业务中,我有 3 个步骤来定义一个人...在每一步中我都会从我的人那里获取一些信息... 例如,我在步骤 1 中获取名字和姓氏,在步骤 2 中获取人物类型并获取其他信息 在步骤 3 中...
我使用来自过渡 UI 的向用户显示步骤,并使用来自 Fluidkit
的任何步骤我有一个用户控件...我如何将我的用户控件绑定到一个 ViewModel?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题不是很清楚,但是是的,您当然可以对多个不同的视图使用相同的 ViewModel 实例。
但是,您也可以将数据保存在模型对象中,并让 ViewModel 只是其上的薄包装。因此,例如,您可以拥有一个 Person 对象,并拥有一个 PersonWizardStepOneViewModel,其属性可以从 Person 读取值并将值写回 Person(添加任何适当的视图模型逻辑,例如基于其他选择启用/禁用按钮等)、PersonWizardStepTwoViewModel 等,并传递 Person 而不是共享相同的 ViewModel。
这取决于你以哪种方式去做。如果逻辑没有变得太复杂并且 viewmodel 类没有变得太大,那么使用单个 ViewModel 实例可能就可以了。如果视图模型开始变得太大而无法舒适地使用,请将其拆分。
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.