Geeks With Blogs

News One world, one team, one goal - let's win!

mukapu
| Home |

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

Posted on Friday, March 12, 2010 1:05 AM | Back to top


Comments on this post: User prompts (MessageBox) with MVVM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Can you put the code somewhere else? IE8 tells me it is unsafe to get it from there.
Left by Nick on Mar 15, 2010 8:16 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
I really didn't know where else to upload it. Give your email, will send it to you.
Left by mukapu on Mar 15, 2010 8:47 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Download link is updated.
Left by mukapu on Apr 25, 2010 7:56 PM

# re: User prompts (MessageBox) with MVVM
Requesting 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.
Left by Mick on May 04, 2010 12:43 AM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
One of the best solutions that I found for controlling message box from view model.

Thanks
Ramesh S
Left by Ramesh Shanmugam on Apr 15, 2011 7:47 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Hi thanks for the article, Can re-upload the source plz, I tried folowing your insights but I can't quite arrange the binding between button action with the trigger property of the messageBox. Can you help me plz.
Left by M on Jun 13, 2012 12:13 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Hi,
I like your solution as well, but as Im new in WPF the screenshots provided on website are not enough for me. Unfortunately I cant upload UserPrompt.zip from your wbesite because of unrecognized error. Could you send it to me by e-mail.
Thanks in advance for assidstance.
Jacek L.
Left by Jacek Liber on Jun 18, 2012 3:26 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
I like your solution it's plain and simple. Please send it to me by e-mail. Thanks!
Left by Jeff C. on Jan 10, 2013 9:51 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Hi, i'm having a little trouble to understand how you define the ControlTemplate of your MessageBox. Could you provide me with the source code?

Thanks
Roper
Left by Roper on Feb 17, 2013 10:52 AM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
The link to download is broken. Can you please email me this solution? Appreciate it. Thanks!
Left by Ritesh on Mar 13, 2013 5:49 AM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Greate solution. Thanks. Can you email me the solution? the link is broken.

TIA,
jim
Left by jim on Apr 25, 2013 12:08 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Your article is fine. But i think, the link is brocken again. Please email me or reup the example

Thanks
Left by Michael on Jun 09, 2013 7:59 PM

# re: User prompts (MessageBox) with MVVM
Requesting Gravatar...
Hi, interesting article. But the link is broken. Please mail me the example or upload it again.
Left by Y. on Dec 09, 2014 10:09 PM

Your comment:
 (will show your gravatar)


Copyright © mukapu | Powered by: GeeksWithBlogs.net | Join free