1
votes

I'm showing a dialog box in my main viewmodel (and view) when mvvm-light message DialogMessage is received. In another viewmodel I call a service, with confirmation dialog like this (as a command result):

DialogMessage message = new DialogMessage(() =>
        {
            myService.Call(var); // if dialog message is confirmed

        }, String.Format("Confirm?", value), Visibility.Visible);

Messenger.Default.Send<DialogMessage>(message);

And this works fine. Now, how can I show another DialogMessage after this, e.g. to show dialog with message that show service myService.Call(var) result ?

Or, in another variant, how can I call a method, after a RelayCommand method execution ?

1

1 Answers

0
votes

So for starters, I've read that using dialog messages is a no no in MVVM. It kind of breaks the concepts of MVVM. The View Model shouldn't have a direct interface that supersedes the view and presents a dialog box. Really, the proper way of doing this would be creating a viewmodel/view for the "dialog box" you want to show.

That being said, if you still want to follow your design, all you would need to do is to register the message wherever you want the message to be received. So depending upon what is encapsulated in that message, you would need:

Messenger.Default.Register<DialogMessage>(
this,
message =>
{
  // Do something
});

Cheers!