具有相同 ViewModel 的多个视图 [英] Multiple Views that have same ViewModel

查看:70
本文介绍了具有相同 ViewModel 的多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序业务中,我有 3 个步骤来定义一个人……在每一步中,我都会从我的人那里获得一些信息……例如,我在第 1 步中获取名字和姓氏,在第 2 步中获取 persontype 并获取其他信息在第 3 步中...

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...

我使用 from transition UI 向我的用户显示步骤并使用 from Fluidkit

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

对于我有一个用户控件的任何步骤...如何将我的用户控件绑定到一个 ViewModel?

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

推荐答案

你的问题不是很清楚,但是是的,你当然可以将同一个 ViewModel 实例用于多个不同的视图.

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

但是,您也可以将数据保存在模型对象中,并让您的 ViewModel 只是在其顶部进行薄包装.因此,例如,您可以拥有一个 Person 对象,并拥有一个 PersonWizardStepOneViewModel,该模型具有从 Person 读取值并将值写回 Person 的属性(添加任何适当的视图模型逻辑,例如基于其他选择启用/禁用按钮)等)、PersonWizardStepTwoViewModel 等,并传递 Person 而不是共享相同的 ViewModel.

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.

这取决于你怎么做.如果逻辑不会变得太复杂并且 viewmodel 类不会变得太大,那么使用单个 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.

这篇关于具有相同 ViewModel 的多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆