The problem statement:
I am tired of thinking how to show a simple message box or user prompt and act based on the response in Model-View-View-Model (MVVM).
– It’s ok, let’s just do this one thing from ViewModel and mock this out for unit testing
– Design my own dialog, then what to do from there
– Can I write something in view code behind, ah yes, that seems to be the only way out, as anyway MVVM is still not matured…
– and what not?
I am pretty much one among the few frustrated out in this world looking for some convincing answers. I think we can do it a little neater without having the feeling of violating any of our self defined rules
– Implement a simple control with no designer visibility.
– Allow a property to be bound to tell when to show the MessageBox
– Provide command binding for possible user actions, Yes, No, Cancel…
How do I Use?
– Just place the necessary XAML tag in the view
– Implement the command for all user actions in the View Model
– Run unit tests on the commands
I am also attaching the code for the MessageBox control and a demo application.
Hope this is useful to somebody out there… Comments are welcome….