What are the biggest pain points with the ViewModel pattern?

1k Views Asked by At

Glenn Block and I have been working together on the ViewModel pattern. We’ve been trying to identify the biggest pain points associated with the pattern, with the goal of adding framework support to alleviate the pain.

Tonight, Glenn posted, “View Model” – the movie, cast your vote. We want to hear from you. Please post here (and vote) on what the biggest pain points are with implementing the ViewModel pattern (also known as Model-View-ViewModel or MVVM). Tell us how the framework can make you life easier!

We are looking at both WPF and Silverlight.

So tell us, what do you want the framework to do to make ViewModel easier?

4

There are 4 best solutions below

1
On
  • Object explosion (Now we have both the model and a view model).
  • Mapping the model to the viewmodel and vice versa.

I think both are neccesary evils, but they are pain points.

0
On

INotifyCollectionChanged supports notification about range of changes, but all WPF collection controls throw range not supported exception when you try to post range update. This means that if you add 10 items to container, the layout is re-evaluated 10 times, which is pretty slow with complex controls!

Solution would be to add SuspendNotifocations and ResumeNotifications methods to Observable collection, and to make all WPF controls aware of range updates (use case: suspend, add items, resume, all items are drawn at once).

1
On

Too many properties to create in ViewModel class. At least what I have saw, for each property of UI element you want to access/bind you need to create property in ViewModel that is too much code to maintain.

1
On

Collections.

I want my Model to have a collection of other Model objects, but bind my GUI to a collection of ViewModel objects.

I can create an ObservableCollection<TViewModel> in my ViewModel layer, and manually populate that with a ViewModel for each item in the Model-level collection. That works fine -- when the program starts up. But then what happens when the user clicks the Add button? Or the Delete button? Or Move Up / Move Down? Etc.

Yes, I can write code to keep the ViewModel list in sync with the Model list, but there are a lot of subtle edge cases, and it's a lot of work (and a lot of tests) to get all the details right. This is a common scenario and should be baked into the framework. (Please?)