How to initiate user interaction outside of the view model?

Topics: Prism v4 - WPF 4
Jun 7, 2012 at 7:02 PM
Edited Jun 7, 2012 at 7:04 PM

I'm not sure if I'm doing it wrong but I have a Controller that I would like to be able to ask the user for input. I've looked through the Advanced MVVM sections on an interaction service and interaction request.

It seems that one method I could do is implement a service that I could use to request user interaction. But from reading the book and the forums an interaction request seems to be the preferred method. I'm not entirely sure how interaction requests work, but in the examples I've seen and downloaded they always bind to it from the view to the viewmodel in some way.

My problem is that I have neither a view or viewmodel in this instance. My controller does the following:

1. It interacts with the menu service to add commands to the application's main menu

2. It creates views for the module and subscribes to events that handle showing the views and hiding the views

The menu commands allow the user to select a view for the module to show it. They also allow the user to create a file or open a file. This is where I need user interaction to ask the user for a filename etc.  The controller register's these commands with the menu service by giving it {text, command, image uri, etc.}.  The MenuService is completely separate and realizes the menu via data templates in a resource file. Its template will bind to the command which is implemented in the Controller. This "open file" command would need to interact with the user more.

1. Is it incorrect for my Controller to want to interact with the user?

2. What's the best way to do it? Is it possible with interaction requests? Without XAML?

3. How do I create a custom dialog to handle the interaction request?

I've looked at all the examples but they ALL assume that I'm trying to interact from the ViewModel and have a View that is bound to it. I have neither...?

Jun 8, 2012 at 2:13 PM


Based on my understanding using the Interaction Requests approach, is useful when you want to preserve a clean separation between the view model and the view, as the view model will encapsulate the presentation logic and the view will handle the visual aspects of the interaction. Basically, in this approach the view model exposes an event that can be raised to the view, and in the view the InteractionRequestTrigger binds to the exposed event in your view model, firing the defined behavior when the raised event happens.

Hence, in your case as you don't have a view or a view model, this approach might not be suitable.

Also, for more information about Interaction Requests, I believe you could find the following blog post interesting:

On the other hand, based on my understanding of your scenario, using an Interaction Service to keep separation of concerns by encapsulating the visual implementation of your desired interaction in a separated service component, which could be consumed by your Controller seems to be a valid approach.

Take into account that the custom implementation of this service will depend on your personal preferences and the requirements of your scenario. For example you can achieve this by using a MessageBox or by showing a modal pop up window in it.

One thing you should  considered, as mentioned in the related section of the Prism documentation (Using an Interaction Service), is passing a callback when calling the service, this way you could have an asynchronous implementation, which will allow you to react when the interaction completes.

I hope you find this handy,

Agustin Adami

Jun 8, 2012 at 2:22 PM


This helps a lot. I had finally figured out the interaction requests example after searching around yesterday and downloading "in the box" which has a WPF example (book only has silverlight, WPF doesn't include default implementations). After figuring it out, I noticed that indeed the view itself was specifying exactly how to display the custom dialog. My reaction was something like, screw it just use a service it will be easy, but I still wasn't sure that would be the best approach. It is good to hear your understanding of it because that really helps me understand that it is likely the best choice in my scenario.