简体   繁体   中英

How to handle multiple windows and dialogs in MVVM?

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?

那就是我在mvvm中使用对话框时所做的事情:)

var result = this.uiDialogService.ShowDialog("Dialogwindow title goes here", dialogwindowVM);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM