InteractionRequest Fails to raise on view

Topics: Prism v4 - WPF 4
Sep 14, 2011 at 7:55 PM

I have a controller class that is managing an import process.  The controller has reference to my ShellViewModel that was injected by Unity.  My ShellViewModel has an ShowErrorMessage() method that raises an InteractionRequest that when raised causes the ShellView to display a notification popup.  The pop up works just find as long as the ShowErrorMessage() method is called from the ShellViewModel directly.  However, when my controller calls ShellViewModel.ShowErrorMessage() the popup is not displayed.  Why is the InteractionRequest ignored unless called from within the ViewModel?

I register the ShellViewModel in the module as a singleton, so I am always getting the same view model that is injected into the ShellView:

_container.RegisterType<ShellViewModel>(new ContainerControlledLifetimeManager());

In my controller class I am calling the ShowErrorMessage() on the ShellViewModel.

        private void ShowImplanUploadErrorMessage(string errorMsg)
            _shellViewModel.ShowErrorMessage(errorMsg, "Import Failed");

Here is the ShowErrorMessage() in my ShellViewModel:

        public void ShowErrorMessage(string message, string title)
            NotifyRequest.Raise(new Notification {Content = message, Title = title});
Sep 15, 2011 at 5:27 PM


Based on my understanding it´s likely that your problem is caused by a threading issue. Therefore, you should make sure that you are calling the method you mentioned on your ViewModel from the UI Thread; if you plan to modify anything that will affect UI state, you will need to dispatch the response to the UI thread, typically using the thread Dispatcher.

You'll find more information regarding that in the following link of the Prism documentation:

If you can't find a solution to your problem by reading the aforementioned suggestion, it would be helpful if you could provide us with a repro sample application, so that we can help you further with this.

Agustin Adami