How to refactor viewmodels

Tag: mvvm , prism Author: gc20090902 Date: 2012-07-28

Currently i am working on a project using prism where one of our modules has a viewmodel with 3000 lines of code!!!. really I would split this class to little pieces (some time is hard to read the code inside of this viewmodel) Actually the code of the viewmodel has more less 30 properties related with commands and i think there it's good place to start.. (some idea how can i move these commands to other class?) any ideas? Thank you!

Best Answer

There are a few things you can do, firstly how much of the code should be in the view model, and how much of it should be in the model itself?

Secondly, can any of the code be part of services that the view model takes as a dependency?

Thirdly, you might want to consider a conventions based MVVM framework such as Caliburn.Micro which will allow you to use actions instead of WPF commanding, which means considerably less boilerplate code binding up verbs on your view model with events on your view, as well as other advantages.