yesterday i used google to find a few ways to make an awesome reusable modal dialog in WPF with PRISM 4.1 and the MVVM pattern. I found some examples but i must say non of those were as "pretty" as i liked them to be.
This one: WPF Modal Dialog (no mvvm -> no use)
This is pretty nice: Showing Dialogs when using the MVVM Pattern (but still it's using a selfmade ServiceLocator which i don't need as i am using the IUnity Container. I could use the logic and rewrite it to Unity but that's not the "pretty" way in my honest opinion.
Well after a while searching the web for informations some blog (can't find the source right now) told me that the PRISM Framework got something called "interaction requests". So i checked out the prism documentation and found a small part under the topic "advanced mvvm scenarios" but the information given in the documentation aren't enough.
I'd like to know if somebody have any good example or any good blogpost about how to realize an awesome modal dialog in prism wpf with mvvm.
EDIT: Regarding the question in the comments:
What makes a modal dialog awesome?
Indeed a good question.
- It must be modal (while the dialog is open the rest of the UI should be freezed)
- The dialog view can have it's own viewmodel or at least i would like to give an instance of an object to the dialog view and return an object back to the parent view
- The view should be an own "xaml" file
- the dialogresult feature from .NET or at least a way to get a response what the user clicked in the dialog
Window.ShowDialog()
doesn't freeze the UI. Rather, it blocks the user input from going into the parent window by disabling it, and then starts a nested modal message loop (newDispatcher
frame). All that happens on the same UI thread. So, it behaves much the same as WinFormsForm.ShowDialog()
. – noseratioThread.Sleep(10000)
would freeze the whole UI. CallingWindow.ShowDialog()
would disable the user input from coming into the parent window, but it won't freeze it. You can even update the UI of the parent window from the modal dialog. Open Visual Studio and do Help About from the menu, is that the kind of the dialog you're looking for? – noseratio