This project has moved and is read-only. For the latest updates, please go here.

DialogMessage and Dialog Boxes

Apr 14, 2010 at 4: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.

Apr 18, 2010 at 9:48 PM


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



Apr 19, 2010 at 10: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 11:57 PM

awesome - this helped me as well.

May 5, 2010 at 5:14 PM


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??"                





May 5, 2010 at 5:24 PM


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?



Jun 15, 2010 at 5:52 PM


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

Sep 23, 2010 at 12:50 PM

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

Dec 4, 2010 at 9:06 PM

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



Feb 6, 2011 at 5: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 3: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 9: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?



Nov 17, 2013 at 10:38 PM
Edited Nov 17, 2013 at 10: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, 2014 at 10:40 AM
Hi Laurent.
Link for is broken. Could You please fix it.
Mar 4, 2014 at 1:17 PM
Fixed, sorry about the inconvenience
Apr 7, 2014 at 6: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
Jan 13, 2015 at 8:11 AM
It took me quite long time to get as much informations about MVVM pattern with user input dialogs (MessageBox, OpenFileDialog, etc.) as possible. Solutions I found were either too much complicated or involved lot of XAML code which I really hate.
My solution is about creating dialog service which is class that have references to UI namespace and have method to get needed values. This method get values from user by showing appropriate user interface.
Dialog service instance is injected into viewmodels using SimpleIoC container and then used inside viewmodel when needed.
I think this approach is good, what do you think?

P.S. I love MVVM Light framework, it is very simple yet very powerful. Things like Unity, Prism or Windsor are overengineered monstrosities.