MVVM ViewModel的许多属性 [英] MVVM ViewModel lots of properties

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

问题描述

我是MVVM的新手,正在开发一个应用程序.我有很多属性的窗体视图.大约50.我不能将它们分开给用户控制,因为我会破坏mvvm的原理.

我无法将它们分成模型,因为它们包含逻辑. PropertyChange,Error change和这些不是poco类,也不是模型.

如果我在同一个视图模型中保留60个属性,那会很好吗?

我认为这不对吗? 您将如何组织这些?

解决方案

我无法将这些内容分离到用户控制中,因为我会破坏mvvm原理.

我不确定您的意思.本质上,您将需要使用视图组合并将视图模型和视图分解为固定部分.

视图是WPF UserControl(或Window),因此,如果您使用的是MVVM,那么您使用的是UserControl,则从概念上讲,它们被视为模式中的视图.

我还建议您如果您使用的是MVVM模式,请使用MVVM框架,以及类似 Caliburn.Micro 之类的工具,可以使视图组合变得异常简单.

我也不建议对视图模型使用依赖项属性,使用INotifyPropertyChanged代替

大多数MVVM框架提供了一种基本视图模型类型,其中包括基于lambda的方法来调用PropertyChanged事件,从而有助于重构.

I am new in MVVM and I am developping an application. I have a form view with a lot of property. About 50. I can not seperate these into usercontrol because I would break the mvvm principles.

I can not seperate these into model, because these contains logic. PropertyChange, Error change and these would not be poco classes, and these are not the model.

Would it be nice If I kept 60 property in a same viewmodel?

Do I think it wrong? How would you organize these?

解决方案

I can not seperate these into usercontrol because I would break the mvvm principles.

I'm not sure what you mean by this. Essentially you'll want to use view composition and break down the view model and views into constiuent parts.

A view is a WPF UserControl (or Window), so if you're using MVVM then you're using UserControl's, it's just conceptually they are considered as views in the pattern.

I would also recommend that you use an MVVM framework if you're using the MVVM pattern, and something like Caliburn.Micro makes view composition incredibly easy.

I would also not recommend using dependency properties for view models, use INotifyPropertyChanged instead.

Most MVVM frameworks provide a base view model type which includes a lambda based method to invoke the PropertyChanged event, thus aiding refactoring.

这篇关于MVVM ViewModel的许多属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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