wpf - Confused about navigation in modal / non modal windows in prism - Need guidance -


i confused going implementing in prism. scenario in 1 liner how achieve prism navigation (regionmanager.requestnavigate) in view shown separate modal/non modal window on main window.

taking code this article, able show separate window, confused navigating in regions of window shown. try put code below clarify situation.

this code in roombandviewmodel launches dialog

private void manageroomfacility() {     dialogservice.showdialog<roomfacilitymainwindowview>(this, container.resolve<roomfacilitymainwindowview>());     regionmanager.requestnavigate(regionnames.main_region, new uri("roomfacilitymainview", urikind.relative)); 

as can seen, launch dialog shows view (code shown below), , tries navigate in 1 of region of view

the popup window roomfacilitymainwindowview

<window x:class="hotelreservation.main.view.roomfacilities.roomfacilitymainwindowview"      <view:roomfacilitymainview          prism:regionmanager.regionname="{x:static const:regionnames.window_main_region}"/>  </window> 

usercontrol within window (roomfacilitymainview)

<usercontrol x:class="hotelreservation.main.view.roomfacilities.roomfacilitymainview"     <grid verticalalignment="stretch" >         ...         <border grid.column="0" style="{staticresource regionborderstyle}">             <stackpanel>                 <textblock text="some sample text"/>                 <contentcontrol prism:regionmanager.regionname="{x:static const:regionnames.window_list_region}"                             />             </stackpanel>         </border>          <gridsplitter width="5" grid.column="1" horizontalalignment="stretch" />          <border grid.column="2" style="{staticresource regionborderstyle}" >             <tabcontrol x:name="items" margin="5" prism:regionmanager.regionname="{x:static const:regionnames.window_edit_region}"  />         </border>      </grid> </usercontrol> 

code behind (roomfacilitymainview.xaml.cs)

public partial class roomfacilitymainview : usercontrol {      public roomfacilitymainview() {         initializecomponent();          roomfacilitymainviewmodel viewmodel = this.datacontext roomfacilitymainviewmodel;         if (viewmodel == null) {             viewmodel = servicelocator.current.getinstance<roomfacilitymainviewmodel>();             this.datacontext = viewmodel;         }     } } 

roomfacilitymainviewmodel public class roomfacilitymainviewmodel : bindablebase {

    iregionmanager regionmanager;     iunitycontainer container;      public roomfacilitymainviewmodel(iregionmanager regionmanager, iunitycontainer container) {         this.regionmanager = regionmanager;         this.container = container;          regionmanager.requestnavigate(regionnames.window_list_region, new uri("roomfacilitylistview", urikind.relative));      } } 

with code no navigation occurs , blank window. contents of roomfacilitylistview.xaml should displayed, blank.

if code confusing, please give advice on how navigate (use requestnavigate) view has regions shown through dialog service separate window instead of on mainwindow(shell) .

if you're using idialogservice implementation shows new window via window.showdialog() method, there's no surprise navigation doesn't work. showdialog() method returns on closing window, navigation request processed on closed window, in particular after window has closed.

there nothing special in modal windows prevent using prism regions , navigation in them. 1 limitation cannot create multiple window instances "as is", since have regions same names, , that's not possible using 1 region manager. however, there solution: scoped region managers.

assuming you're not going create multiple instances, here example how solve issue.

first, have ensure modal dialog's regionmanager same instance main regionmanager (i'm using mef here, doesn't matter):

[export] public partial class dialog : window {     private readonly iregionmanager rm;      [importingconstructor]     public dialog(iregionmanager rm)     {         this.initializecomponent();         this.rm = rm;          // don't forget set attached property instance value         regionmanager.setregionmanager(this, this.rm);     } } 

now, extend dialog service implementation method accepts navigation callback:

bool? showdialog<t>(object ownerviewmodel, object viewmodel, action initialnavigationcallback = null) t : window {      window dialog = /* instance creation code, e.g. using container */;     dialog.owner = findownerwindow(ownerviewmodel);     dialog.datacontext = viewmodel;      if (initialnavigationcallback != null)           {         dialog.loaded += (s, e) => initialnavigationcallback();     }      return dialog.showdialog(); } 

this provide possibility display dialog initial navigation request, can call e.g. this:

void manageroomfacility() {     dialogservice.showdialog<roomfacilitymainwindowview>(         this,          container.resolve<roomfacilitymainwindowview>(),         () => regionmanager.requestnavigate(             regionnames.main_region,              new uri("roomfacilitymainview", urikind.relative))         ); 

alternatively, can use state based navigation task. there sample implementation of send message modal dialog in state-based navigation quickstart.

<prism:interactionrequesttrigger sourceobject="{binding sendmessagerequest}">     <prism:popupwindowaction ismodal="true">          <prism:popupwindowaction.windowcontent>             <vs:sendmessagepopupview />         </prism: popupwindowaction.windowcontent>     </prism:popupwindowaction> </prism:interactionrequesttrigger> 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -