MVVM ViewModel lots of properties

孤街浪徒 提交于 2019-12-05 18:45:08

问题


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?


回答1:


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.




回答2:


Please don't use PropertyChanged for 60 Properties. Use DependencyProperty. For terms of usabilty use the propdp Shortcut from Visual Studio and press Tab twice.

Please refer to this link: http://www.codeproject.com/Articles/62158/DependencyProperties-or-INotifyPropertyChanged



来源:https://stackoverflow.com/questions/17143842/mvvm-viewmodel-lots-of-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!