User prompts (MessageBox) with MVVM
Posted
by mukapu
on Geeks with Blogs
See other posts from Geeks with Blogs
or by mukapu
Published on Thu, 11 Mar 2010 20:05:11 GMT
Indexed on
2010/03/11
19:39 UTC
Read the original article
Hit count: 286
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).
Common approaches:
- 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!
Solution:
The Control
- 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 tags in the view
- Implement the command for all user actions in the View Model
- Run unit tests on the commands
© Geeks with Blogs or respective owner