SL5 + MEF + PRISM + DataGrid + Edit Rows in Modal Dialog: Is InteractionRequest the Answer?

Topics: Prism v4 - Silverlight 4
Aug 31, 2012 at 3:01 AM

I am in the process of re-writing one of our large Silverlight apps to use PRISM and the MVVM design pattern.

A very common scenario is a DataGrid in the View. Double clicking a row allows the user to edit the entity represented by the row, using a ChildWindow.

I am tempted just to capture the DoubleClick event in the code behind, create a new ChildWindow of the proper type, and set the DataContext to be DataGrid.SelectedItem.

I know that this is not the proper way to handle this scenario with PRISM and MVVM, however.

I would love advice on what is! (re: my seems like InteractionRequest might be the best way to do this?  I don't clearly see what I gain by doing it that way though...)


Aug 31, 2012 at 5:25 PM


Based on my understanding, using InteractionRequests to achieve the functionality you are describing seems to be a valid approach which also keeps a clear separation of concerns between the view and view model.

You can read more about the benefits of using InteractionRequests in a MVVM scenario in the following article by Brian Noyes:

For example, your view model could expose through properties an InteractionRequest and a Command, which would raise the InteractionRequest when invoked. Then, the view could implement an InteractionRequestTrigger that would bind to the InteractionRequest property of the view model, and you could also bind the SelectedItem property of the DataGrid to a property in the view model so that it is aware of which item of the DataGrid is selected. Also, you could use an InvokeCommandAction in the view to listening the corresponding event and invoke the aforementioned Command in the view model when that event is raised.

By doing this, the view model would be in charge of when the interaction should be requested and the information to be used for that interaction, while the view would be in charge of presenting the interaction to the user.

You can find more information about InteractionRequests in the aforementioned blog post and in the following chapter of the Prism documentation:

I hope your find this useful,

Damian Cherubini