MVVM ViewModel lots of properties

2019-04-06 07:06发布

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?

2条回答
乱世女痞
2楼-- · 2019-04-06 07:30

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.

查看更多
▲ chillily
3楼-- · 2019-04-06 07:39

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

查看更多
登录 后发表回答