views:

55

answers:

2

In a GUI app using MVP/MVVM, say the Presenter/ViewModel presents a list/collection, and one or more of the items can be selected at a time. Because other parts of the application could conceivably change as the selection changes, does the selection require its own Presenter/ViewModel? If not, how is selection best handled by a given Presenter?

(This is conceptual and not specific to Microsoft's WPF, etc.)

+1  A: 

I would say within the selection itself it does not require its own presenter/viewmodel but the overall view that contains the list would capture what the selection is.

Since you have other parts of the application responding to the selection then these views would have their own presenter/viewmodel to deal with the specific selection. These other views would receive an event when the selection property changes. If you need to create a new view based on the selection I would have a Controller listening to this event as well.

This scenario is typically done within composite applications and plugable views. Although you don't need to go down the fully composite route you can easily implement the EventAggregator pattern that these applications use.

Have a look at the EventAggreator described within. Although it is Prism you can have the pattern implemented within your application relatively easily.

aqwert
+1  A: 

The BookLibrary sample application of the WPF Application Framework (WAF) shows how to handle selections in a MVVM application.

jbe