dialog window with result

Topics: Prism v4 - WPF 4
Jan 23, 2012 at 7:01 PM

I know there are a lots of samples unig region manages and interaction request triggers to show dialogs using prism, WPF and MVVM. in my situation I have different modules. For example I have module which creates organization units and assigns executive person to newly created unit. this view needs to be shown in standard dialog window with returned object of Model type which is OrganizationUnit object in this case. after showing view in modal window it has an textbox input here executive person name is entered and in case no matching person found it needs to open another dialog window which creates person and returns created object to already opened dialog window. I have seen all examples of using dialogs in MVVM as well as using popup region behavior and interactionrequesttrigger in PRISM. I do not get much out of using custom control to show popup as all I need is standard showdialog method which can be called from any viewmodel with callback specified.

the way I want to achieve this is to have interactionrequesttriger in my shell and initial call to open popup dialog is performed on this trigger. to not to make this all very complicated I want some centralized way of showing dialogs and within dialogs showing other dialogs and all this with callbacks. could someone point me to the right direction?

By The way I want to have single control DialogView which will have ContentControl where viewmodels inject their views and buttons placeholder which holds buttons; Ok, Cancel, Apply and want to bind have them bind to loaded viewmodels commands.

I know all this sounds a little bit complicated and complex but there might be solution for this. please someone give me ideas of how to accomplish this task.

Developer
Jan 23, 2012 at 8:13 PM

Hi,

If I understood you scenario correctly, you basically want to show a dialog window which contains a region for views and a place holder for buttons. Also, this dialog window should be able to show its own dialog windows and all should be able to invoke a call back in the previous dialog when task performed in the dialog is done.

As a possible approach, you could create a shared service that would be in charge of showing the dialog windows and passing them the corresponding callbacks. The dialog could be a window that could contain a region for its content (possibly with a scoped region manager) and the aforementioned place holder for buttons. For example, each dialog window could be an instance of that class. Then, when an interaction request is raised, the interaction request trigger could use this service to raise the dialog. However, take into account that the implementation details for this will depend mostly of your personal preferences and the requirements of your scenario.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Jan 23, 2012 at 8:22 PM
Edited Jan 23, 2012 at 8:52 PM

Thank u for your answer. this is something I think of but without regions. I think of creating some IDialogService for this and use it to show dialogs but can not make code architecture. could u please provide some pseudo code on how to implement this? this other problem I see to be complicated is that each view loaded in a dialog window needs to set that window as a parent to another child window if that is open from already opened dialog window. I am not ver good at actions and triggers and this makes my live a bit difficult but as I understan I need to overid some getDefaultWinow or something like this method to return new dialog window right? as This ChildWindowAction is only silverlight implementation . I am looking way to use window.showdialog() in WPF. some pseudo cod will be great help for me.

and I want to have something like this in my viewmodel

 DialogService.Raise(new Confirmation { Content = ViewModel},
                confirmation =>
                {
                    if (confirmation.Confirmed)
                    {
                    }
                });

here Viewmodel implements IViewModel and it has IView property so dialog window could us this viewmodel to set window content . but setting buttons and commands for each button based on viewmodel still seems mysterious for me. as there will not bee more buttons only OK Cancel Apply and each Viewmodel must set appropriate delegate command for these buttons

I even this if it is possible at all?

Jan 24, 2012 at 6:15 PM

does not anyone know some better solution or could one provide with pseudo code fr my problem?

Developer
Jan 25, 2012 at 6:43 PM

Hi,

The functionality you are mentioned is not supported by Prism as out of the box. As mentioned in Chapter 6: Advanced MVVM Scenarios - Using Interaction Request Objects, Prism provides the InteractionRequestTrigger and PopupChildWindowAction classes as a basis for the development of your own triggers and actions.

However, based on my understanding of your requirements, I believe you might find the following thread interesting:

In the aforementioned thread you will find a repro sample application portraying a scenario where a modal dialog, with a specific view model, is shown through an interaction request. Following this sample, you could have various Windows that you could use as your dialogs, and show the appropriate one for each situation.

Although the code provided in the aforementioned link is targeted for Silverlight, I believe it could be ported to WPF without problems.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini