I use the Stocktrader RI RegionPopupBehavior technique to implement a "popup region" in my application to open several views in a new window.
This works so far, but I wanted the new opened window to lock the main region behind it, so I wanted a
modal window instead a normal window. I changed the Show() method in WindowWrapper.cs to call
this.window.ShowDialog() instead of this.window.Show(), which brought the required functionality. Works as well, but with one drawback: Doing so, I am not able any more to publish events to the new window using EventAggregator. I have the following
regionManager.RequestNavigate(RegionNames.PopupRegion, new Uri("/TestView", UriKind.Relative));
In the TestView constructor, I subscribte to the Event, but using a modal window (ShowDialog), the event is not published until the modal window is closed. So code execution is halted on regionManager.RequestNavigate till the window is closed.
Any guess, how to solve this?
Is it possible to use a modal window with working EventAggregation?
Mar 1, 2011 at 3:39 PM
Since the behaviour of the Modal Window is synchronous, the execution is halted until you close the window. One possibility would be to fire the event before calling the
RequestNavigate method, or in the OnNavigatedFrom
method of the view that is in place before calling the modal window.
Other than that, there are no known issues with Event Aggregation when using modal windows. It's possible also to publish events from within the modal window.
You might also find the following blog post by Tim Heuer useful:
Refactoring Silverlight ChildWindow for a non-modal use
I hope you find this helpful.
Guido Leandro Maliandi
I feel your pain. I had similar problems with dialogs in our WPF - MVVM - PRISM app. As Guido said, the ShowDialog() method is synchronous. This unfortunately has the unwanted behavior of blocking the prism navigation pipeline. When
I added a ShowDialog method to the WindowWrapper class, the OnNavigatedTo method of the INavigationAware interface that was implemented in our view models didn't get called until the dialog was closed. The view models were relying on the OnNavigatedTo
methods to get called for retrieving data from the navigation context. I found a way using some Win32 dll calls to create a non-blocking modal window, but had a few issues with the behavior of nested dialogs. In the end I called the BeginInvoke
method on the dispatcher to call the show dialog method. So below are my two methods in the WindowWrapper class one for show as non-modal and one for showing a modal dialog.
Good luck, and I hope that helps you.