1

Is there any standard method for showing dialog windows, opening and closing them and retrieving data from them, using the MVVM pattern?

I have seen this:http://www.daedtech.com/mvvm-and-dialogs

I want use for show a dialog for special (View/ViewModel).

How to handle multiple windows and dialogs in MVVM?

Niloo
  • 1,205
  • 5
  • 29
  • 53
  • I read the link but found it curious that the author was placing so much emphasis on how to open a window. In my opinion that is the most trivial task! All one needs is to create a new instance and call the show method. I personally feel that the difficulty lies in redirecting any data from the 2nd window back to the original view model, and yes... Closing the window without code behind. With the first problem, I pass a reference of my main view model to the child . with the second, I create a event handler and subscribe to it when I open the child window. – failedprogramming Mar 17 '13 at 07:13
  • Refer to this using IoC - http://www.codeproject.com/Articles/36745/Showing-Dialogs-When-Using-the-MVVM-Pattern – Rohit Vats Mar 17 '13 at 07:33
  • Ioc is overkill for his specific case. – David Mar 17 '13 at 11:20

2 Answers2

0

thats what i do when working with dialogs in mvvm :)

var result = this.uiDialogService.ShowDialog("Dialogwindow title goes here", dialogwindowVM);
Community
  • 1
  • 1
blindmeis
  • 22,175
  • 7
  • 55
  • 74
0

The best solution for this case that I ever seen is PRISM's Interaction Request (see "Using Interaction Request Objects" title). It's the most MVVM friendly abstraction for opening dialogs. Interaction request is view model, separated from controls and view elements and can be bound to specific view.

Sample. View Model:

public IInteractionRequest ConfirmCancelInteractionRequest
{
    get
    {
        return this.confirmCancelInteractionRequest;
    }
}

this.confirmCancelInteractionRequest.Raise(
    new Confirmation("Are you sure you wish to cancel?"),
    confirmation =>
    {
        if (confirmation.Confirmed)
        {
            this.NavigateToQuestionnaireList();
        }
    });

View:

<i:Interaction.Triggers>
    <prism:InteractionRequestTrigger 
            SourceObject="{Binding ConfirmCancelInteractionRequest}">

        <prism:PopupChildWindowAction
                  ContentTemplate="{StaticResource ConfirmWindowTemplate}"/>

    </prism:InteractionRequestTrigger>
</i:Interaction.Triggers>

<UserControl.Resources>
    <DataTemplate x:Key="ConfirmWindowTemplate">
        <Grid MinWidth="250" MinHeight="100">
            <TextBlock TextWrapping="Wrap" Grid.Row="0" Text="{Binding}"/>
        </Grid>
    </DataTemplate>
</UserControl.Resources>

Wpf PRISM is here

Vladimir Dorokhov
  • 3,784
  • 2
  • 23
  • 26
  • Thanks a lot, but i don't want to use component. – Niloo Mar 18 '13 at 04:53
  • Create your own simple component for your needs. This sample demostrates a principle and you can use it as example. Also PRISM is open source, so you can add only needed classes into your project. – Vladimir Dorokhov Mar 18 '13 at 08:11