-2

Possible Duplicate:
Handling Dialogs in WPF with MVVM

I have a serious doubt as to how to implement the following.

  1. from the view execute an action binded to my ViewModel
  2. depending on a condition, a request is made to the user

for now I use System.Windows.MessageBox.Show for this purpose, I do not know if this is appropriate and also wish to have a custom dialog.

technique or pattern that can help me with this problem

Community
  • 1
  • 1
rkmax
  • 17,633
  • 23
  • 91
  • 176
  • I would recommend looking into a messaging system such as MVVM Light's `Messenger` or Prism's `EventAggregator` for communication between Views and ViewModels since it will keep the two layers completely separate while allowing communication between them – Rachel Sep 15 '12 at 23:15

1 Answers1

0

Firstly, if you are doing MVVM, then you should be using an MVVM framework. With Caliburn.Micro for example you could either display another window (using the window manager), or display a part of the existing view over the top of the other elements within the view.

Either way, if you want to stick with a message box, then you'll want to work against an abstraction in your view model, so that you can unit test your view models without the tests producing dialogs that wait on user input.

devdigital
  • 34,151
  • 9
  • 98
  • 120
  • i'm using MVVM Light, i need is a way to show a a like "MessageBox" but with better look. – rkmax Sep 15 '12 at 21:21
  • Well, as I say, the best option is to create an interface that your parent view model takes as a dependency, and this interface should provide a method for displaying a dialog, and returning a dialog result. Then, in your implementation you can either instantiate a new modal window, or change a boolean property value on (e.g.) your shell view model that your shell view is bound to which turns on/off an overlay of your dialog view. – devdigital Sep 15 '12 at 21:26