DialogMessage and Dialog Boxes

Apr 14, 2010 at 3:25 PM

Hi all

I've been struggling a bit trying to get my head around creating dialogs using MVVM with the MVVM Light Toolkit, I'm aware of the existence of the DialogMessage class, but have no real idea how to use it.

Would someone be so kind as to describe how you would send a message to a view instructing it to open a dialog box (a simple messagebox with ok/cancel is fine) and then return the result to the caller.

I've been looking everywhere for something but to no avail.

Coordinator
Apr 18, 2010 at 8:48 PM

Hi,

I posted a sample showing a DialogMessage being used. I will blog about it soon.

http://www.galasoft.ch/mvvm/resources/Samples/DialogMessageSample.zip

Cheers,

Laurent

Apr 19, 2010 at 9:51 AM

Thanks again Laurent, this has helped a lot.

One of the problems I've noticed with MVVM as a whole is that there seems to few, if any, examples of a more typical windows applicaiton. Every example I've found seems to focus on a single view rather than any kind of menu driven, multiple windowed application. I can only assume that a lot of this is due to the tendency for a lot of MVVM's proponents being Silverlight developers.

Once I get this project finished I think I'm going to blog about my experiences and hopefully help anyone who finds themselves in the same situation as myself.

Apr 27, 2010 at 10:57 PM

awesome - this helped me as well.

May 5, 2010 at 4:14 PM

Laurent,

I used this sample and apparently I am doing something wrong because the box never appears on my version. What could I be doing wrong? There are no errors.

var message = new DialogMessage("Are you sure want to delete ??", "Confirm Delete", DialogMessageCallback)

{

    Button = System.Windows.MessageBoxButton.OKCancel,

    Caption = "Caption??"                

};

 

Messenger.Default.Send(message);

 


Coordinator
May 5, 2010 at 4:24 PM

Hi,

Sending is one thing, but you also need to receive the message and handle it in the view ;) The message's purpose is not to actually show the dialog, it is to ask the view to show it.

If you check the sample I posted (see above), you will see that in MainPage.xaml.cs, the MainPage receives the message, displays the MessageBox and passes the result to the callback.

The point of the exercise is to separate the concerns: The ViewModel wants a dialog to be shown, but doesn't want to know how. The View just displays the dialog, but doesn't handle the result.

Does that make sense?

Cheers,

Laurent

Jun 15, 2010 at 4:52 PM

Laurent,

Your example helped me a great deal.  Thanks for the fine work you are doing.

Sep 23, 2010 at 11:50 AM

Laurent, I have nothing to add except my thanks for your demo and framework.

Dec 4, 2010 at 8:06 PM

Laurent - great sample and nice solution. Helped me dive into the messaging part of MVVM Light too.

Thanks!!!

Todd

Feb 6, 2011 at 4:27 PM

 

I've implemented a Behavior that listens to a Message from the ViewModel. It's based on Laurent Bugnion solution, but since it doesn't use code behind and is more reusable, I think it's more elegant.

 


Check it out here

Mar 17, 2011 at 2:19 PM

I'm looking to add in a "function pad" type of behavior to my application but not sure how best to accomplish it (DialogMessage? NotificationMessageWithCallback?)..

I've got a list of items (in my example, a list of books from thier collection) presented to the user and have the wiring in place to detect the SelectedBook when the user selects an item from the list. Upon selection, I want to display a popup that presents a list of available functions (mark as read, mark as loaned out, leave review, etc..) to the user. Once the user takes action, I want to simply clear their current selection and remove the popup.

So I either want to override the standard OK, Cancel, etc.. options provided by the standard dialog stuff or perhaps raise a NotificationMessageWithCallback and pass in the ViewModel that contains my SelectedBook, have my view register and respond to that and then hide itself when the user makes a selection but I'm unclear as to how to get the action (mark as read, loaned out, leave review, etc..) back into the callback.

Does anyone have any examples of displaying some sort of user entry view in a popup by using some of the Messaging framework available in MVVM Light where the user response isn't just a simple OK/Cancel?

 

 

Oct 12, 2011 at 8:23 AM

Hi Laurent,

I watched your presentation on the MVVM pattern using MVVM Light and would like to try it in my new WPF application that will be based on the Entity Framework 4.1.

Have you already made any demo on similar case or blogged on it? I'd be glad to take a look.

Do you guys know any example of best practices for using the two together?

 

Thanks

Nov 17, 2013 at 9:38 PM
Edited Nov 17, 2013 at 9:38 PM
How do you use the the dialog boxes that allow for custom buttons(like "yes" or "no") do you have to hook it up to the Xna dialog box or something?
Mar 4 at 9:40 AM
Hi Laurent.
Link for DialogMessageSample.zip is broken. Could You please fix it.
Coordinator
Mar 4 at 12:17 PM
Fixed, sorry about the inconvenience
Apr 7 at 5:23 AM
Hi Laurent,
I'm a fan of yours , appreciated your works very much .

I have looking around samples for how to send a simple notification message with callback , Couldn't get a detailed one.
I'm trying to achieve a folderbrowserTask with this Notification message with callback.
Please bless me with any reference