WPF-用户控件应具有自己的ViewModel吗? [英] WPF - Should a user control have its own ViewModel?

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

问题描述

我有一个由几个用户控件组成的窗口,想知道每个用户控件是否都有自己的ViewModel,或者整个窗口是否应该只有一个ViewModel?

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

推荐答案

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

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.

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

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