开发者

MVVM design Question

开发者 https://www.devze.com 2023-01-30 01:28 出处:网络
I have an application with two forms ( windows ) They represent the front and back of an ID card Users enter data and the printer spits out something that can be folded and lamina开发者_运维百科ted to

I have an application with two forms ( windows ) They represent the front and back of an ID card Users enter data and the printer spits out something that can be folded and lamina开发者_运维百科ted to give the front back effect I am using different Views to show the front and back and I guess my question is how do I use the same ViewModel instance in both( the data needs to be saved to a DB before printing ) Or am I doing this all wrong and I should just have one view and show hide Front\Back ( i really hate that ) Thanks


Generally, you are going to want one ViewModel per View, since the job of the ViewModel is to provide exactly the data needed by the View it is attached to.

So, in your case, it sounds like you should have one View and ViewModel for the front and one View and ViewModel for the back.

There are several ways you could go about saving the data when the user submits the form. A common pattern is to set up Repository classes for each of your database tables. Repository classes typically allow you to select, insert, update, and delete data. So, you could pass the necessary Repositories into each ViewModel, then when the user submits, have the ViewModel tell the repository to insert or update the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号