|
|
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
|
|
|
|
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.
|
|
|
|
awesome - this helped me as well.
|
|
|
|
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
|
|
|
|
Laurent,
Your example helped me a great deal. Thanks for the fine work you are doing.
|
|
|
|
Laurent, I have nothing to add except my thanks for your demo and framework.
|
|
|
|
Laurent - great sample and nice solution. Helped me dive into the messaging part of MVVM Light too.
Thanks!!!
Todd
|
|
|
|
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
|
|
|
|
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?
|
|
|
|
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
|
|