用户控件应该有自己的视图模型吗? [英] Should a user control have its own view model?

查看:34
本文介绍了用户控件应该有自己的视图模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由多个用户控件组成的窗口,我想知道是每个用户控件都有自己的视图模型还是整个窗口应该只有一个视图模型?

I have a window made up of several user controls and was wondering whether each user control have its own view model or should the window as a whole have only one view model?

推荐答案

这不是一个是或否的问题.这取决于拥有额外的视图模型是否可以为您提供更好的可维护性或可测试性.如果它没有给你带来任何好处,那么添加视图模型是没有意义的.您需要衡量开销对于您的特定用例是否值得.

This is not a yes or no question. It depends on whether having extra view models affords you better maintainability or testability. There's no point adding view models if it doesn't gain you anything. You'll need to gauge whether the overhead is worth it to your particular use case.

这篇关于用户控件应该有自己的视图模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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