wpf - Prism Custom Confirmation Interaction -


i created custom confirmation window in app prism unity, wpf & mvvm. need notifications need sent viewmodel. have in detail record view, let's call mydetailview.

<!-- custom confirmation window --> <ie:interaction.triggers>     <interactionrequest:interactionrequesttrigger sourceobject="{binding confirmationrequest,  mode=twoway}">         <mycontrols:popupwindowaction1 ismodal="true">         </mycontrols:popupwindowaction1>     </interactionrequest:interactionrequesttrigger> </ie:interaction.triggers> 

as shown above, made interaction mode=twoway confirmation popup window can send button click result ok or cancel button. confirmation window appears should, don't know how send button click result viewmodel, mydetailviewmodel. main question.

edit: mydetailviewmmodel method raises interactionrequest.

private void raiseconfirmation() {confirmationrequest     .raise(new confirmation()     {         title = "confirmation popup",         content = "save changes?"     },  c =>{if (c.confirmed) { uow.adrtyperos.submit();} 

this popupwindowaction1 class. part of answer question may how implement notification , finishedinteraction methods.

class popupwindowaction1 : popupwindowaction, iinteractionrequestaware {     protected override window getwindow(inotification notification)     { // custom metrowindow using mahapps         metrowindow wrapperwindow = new confirmwindow1();         wrapperwindow.datacontext = notification;         wrapperwindow.title = notification.title;          this.preparecontentforwindow(notification, wrapperwindow);          return wrapperwindow;     }      public inotification notification     {         { throw new notimplementedexception(); }         set { throw new notimplementedexception(); }     }      public action finishinteraction     {         { throw new notimplementedexception(); }         set { throw new notimplementedexception(); }     } } 

is there interaction need put in confirmwindow1, this?

<i:interaction.triggers>     <i:eventtrigger eventname="previewmouseleftbuttonup">         <ei:callmethodaction targetobject="{binding relativesource={relativesource ancestortype=usercontrol}, path=datacontext}"                              methodname="datacontext.validateconfirm"/>     </i:eventtrigger> </i:interaction.triggers> 

do need type of interaction within button? if so, how code needs corresponds particular viewmodel invoked interaction. suggestions? thank you.

main thing is, when raise interaction, provide callback triggered when interaction finished. callback gets notification , interaction should have stored potentially interesting return values there.

here's example...

relevant parts of viewmodel:

public interactionrequest<selectquantitynotification> selectquantityrequest {     get; }  // in handler triggers interaction selectquantityrequest.raise( new selectquantitynotification { title = "load how stuff?", maximum = maximumquantity },     notification =>     {         if (notification.confirmed)             _worldstateservice.executecommand( new loadcargocommand( sourcestockpile.stockpile, cartviewmodel.cart, notification.quantity ) );     } ); 

... , view:

<i:interaction.triggers>     <interactionrequest:interactionrequesttrigger sourceobject="{binding selectquantityrequest, mode=oneway}">         <framework:fixedsizepopupwindowaction>             <interactionrequest:popupwindowaction.windowcontent>                 <views:selectsampledataforimportpopup/>             </interactionrequest:popupwindowaction.windowcontent>         </framework:fixedsizepopupwindowaction>     </interactionrequest:interactionrequesttrigger> </i:interaction.triggers> 

additionally, need class hold data that's passed around, , viewmodel/view pair interaction itself.

here's data holding class (note maximum passed to interaction, , quantity returned it):

internal class selectquantitynotification : confirmation {     public int maximum     {         get;         set;     }      public int quantity     {         get;         set;     } } 

this view of interaction popup:

<usercontrol x:class="clientmodule.views.selectsampledataforimportpopup"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"           xmlns:prism="http://prismlibrary.com/"          prism:viewmodellocator.autowireviewmodel="true"          mc:ignorable="d"           d:designheight="300" d:designwidth="300">     <stackpanel orientation="vertical">         <textblock>             amount: <run text="{binding quantity}"/>         </textblock>         <slider orientation="horizontal" minimum="0" maximum="{binding maximum}" value="{binding quantity}" tickplacement="bottomright"/>         <button content="ok" command="{binding okcommand}"/>     </stackpanel> </usercontrol> 

and it's viewmodel:

internal class selectsampledataforimportpopupviewmodel : bindablebase, iinteractionrequestaware {     public selectsampledataforimportpopupviewmodel()     {         okcommand = new delegatecommand( onok );     }      public delegatecommand okcommand     {         get;     }      public int quantity     {         { return _notification?.quantity ?? 0; }         set         {             if (_notification == null)                 return;             _notification.quantity = value;             onpropertychanged( () => quantity );         }     }      public int maximum => _notification?.maximum ?? 0;      #region iinteractionrequestaware     public inotification notification     {         { return _notification; }         set         {             setproperty( ref _notification, value selectquantitynotification );             onpropertychanged( () => maximum );             onpropertychanged( () => quantity );         }     }      public action finishinteraction     {         get;         set;     }     #endregion      #region private     private selectquantitynotification _notification;      private void onok()     {         if (_notification != null)             _notification.confirmed = true;         finishinteraction();     }     #endregion } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -