| Home |

User prompts (MessageBox) with MVVM

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 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.

UserPrompt.zip

Hope this is useful to somebody out there... Comments are welcome....

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Friday, March 12, 2010 1:05 AM

Feedback

# re: User prompts (MessageBox) with MVVM

Left by Nick at 3/15/2010 8:16 PM
Gravatar Can you put the code somewhere else? IE8 tells me it is unsafe to get it from there.

# re: User prompts (MessageBox) with MVVM

Left by mukapu at 3/15/2010 8:47 PM
Gravatar I really didn't know where else to upload it. Give your email, will send it to you.

# re: User prompts (MessageBox) with MVVM

Left by mukapu at 4/25/2010 7:56 PM
Gravatar Download link is updated.

# re: User prompts (MessageBox) with MVVM

Left by Mick at 5/4/2010 12:43 AM
Gravatar Thank you for taking the time to put this example together, it should certainly help me. I would make mention that this project requires VS 2010.

# re: User prompts (MessageBox) with MVVM

Left by Ramesh Shanmugam at 4/15/2011 7:47 PM
Gravatar One of the best solutions that I found for controlling message box from view model.

Thanks
Ramesh S

Your comment:





 
 

Copyright © mukapu

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski