Dimitri Dimitri - 3 months ago 25
C# Question

Code-Heavy ViewModels in MVVM

I'm writing an application in WPF and found myself loving whole MVVM paradigm. My only concern at the moment is that my ViewModels are becoming heavy. They contain

Commands
, logic to enable and disable buttons, instances of other ViewModels, async method with
DispatchTimer
timers etc. Is this something that is normal in this kind of development environment? Or is there some logical way of organizing ViewModels without becoming too "crowded"?

Answer

Keep in mind that the ViewModel is just an adapter between your model, where logic and data live, and the view which is shown to the user.

The idea is you can easily swap views or change them, without the logic suffering from that.

Having said that, depending on the complexity of your application, they might grow quite big, but if it's mainly stuff that ends up enabling/disabling stuff on your view, and isn't doing logic / processing stuff, I'd say this is where it's supposed to live.