Question: I'm very much new in WPF & MVVM paradigm and i'm trying hard to absorb it. The problem i'm having looks like a lot of MVVM beginers face the same & it seems there's no simple approach. So, to keep the problem domain simple here's just an experimental work.

I have a MainWindow with a "New" button on it. I want to show an instance of a NewWindow.xaml when i click on this button. How can i do this from MainWindowViewModel? Can mediator pattern help? Please suggest any good implementation reference.

I also have a "Close" button on the MainWindow & i want to exit the application when i click this one. And I need help again :(

Answer: 
i did have the same problem a while ago.

at least i use a very simple approach and i'm happy with. [here](https://stackoverflow.com/questions/3801681/good-or-bad-practise-for-dialogs-in-wpf-with-mvvm) is my solution.

in your viewmodel you just have to write one line of code:

```
var result = this.uiDialogService.ShowDialog("Dialogwindow title goes here", newdialogwindowVMgoeshere);
//do what you want with the dialogresult

```
I put dialog code into the View's CodeBehind. I still route the command through the ViewModel, but the ViewModel calls the View's implementation and gets the result.

Suppose I have MainWindow View (xaml), and a MainWindow ViewModel and I want to save a file.

In the codebehind View (MainWindow.xaml.cs) I add the code to create the dialog and return the save filename:

```
    public FileInfo OpenSaveFileDialog(string title, string filter)
    {
        var dialog = new SaveFileDialog
        {
            Filter = filter,
            Title = title
        };

        var result = dialog.ShowDialog();
        if (!result.Value) return null;

        return new FileInfo(dialog.FileName);
    }

```

In the ViewModel I have a DoSaveFile() method:

```
    public void DoSaveFile()
    {
        var file = OpenSaveFileDialog("Save File", "Super files (*.super)|*.super |All files (*.*)|*.*");
        if (file == null) return;
        //Save logic...
     }

    public DelegateCommand SaveFile { get { return Get("SaveFile", new DelegateCommand(DoSaveFile, () => true)); } }

```

In the MainWindow.xaml I have a button bound to to the delegate command:

```
    <Button Content="Save File" Command="{Binding SaveFile}"/>

```

Like MVP, this implementation is chatty, but it works really well for test and separation of concerns. To me, it makes sense to leave the mechanics of window opening to the View class, even thought it feels a bit like an active-view.