views:

663

answers:

4

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  A: 
  • 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.

Daniel Auger
The pattern also looks like it violates DRY (Do not repeat yourself
ArielBH
A: 

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.

This has been my experience. For a View of any complexity, the ViewModel quickly becomes large and cumbersome to maintain/update. The initial creation of the properties can be mostly automated, but it quickly becomes hard to find code in the ViewModel.
Jim Anderson
+4  A: 

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?)

Joe White
The solution I used for this is simply to base model's collections on ObservableCollection as well - you do all adding/removing in Model (where it belongs), and the changes are propagated to VM and GUI.
Tomáš Kafka
A: 

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).

Tomáš Kafka