wpf - Problems with module dependency and eventAggregator on module load in C# prism -
i using prism c# there have problem load of 2 modules. in module tabcontrol itemtemplate , contenttemplate. module b subview of module , in contenttemplate of module a.
xaml of module a
<grid> <tabcontrol x:name="tabcontrol" itemssource="{binding folders}" selecteditem="{binding selecteditem}" horizontalalignment="stretch" verticalalignment="stretch"> <tabcontrol.itemtemplate> <datatemplate> <textblock text="{binding name}"/> </datatemplate> </tabcontrol.itemtemplate> <tabcontrol.contenttemplate> <datatemplate> <contentcontrol prism:regionmanager.regionname="listmodulregion" horizontalcontentalignment="stretch" verticalcontentalignment="stretch"/> </datatemplate> </tabcontrol.contenttemplate> </tabcontrol> </grid>
viewmodel of module a
in viewmodel of module eventaggregator. publish event when other item in tabcontroll selected.
#region private fields ************************************************************************************************** private readonly ideviceservice _deviceservice; private readonly ieventaggregator _eventaggregator; private modulefolder _selecteditem; #endregion #region public properties *********************************************************************************************** public ienumerable<modulefolder> folders { { return _deviceservice.modulefolders; } } public modulefolder selecteditem { { return _selecteditem; } set { _selecteditem = value; onpropertychanged(() => selecteditem); modulefolderchangeevent evt = _eventaggregator.getevent<modulefolderchangeevent>(); evt.publish(selecteditem); } } #endregion #region constructor(s) ************************************************************************************************** public folderselectionviewmodel(ieventaggregator eventaggregator, ideviceservice deviceservice) { _eventaggregator = eventaggregator; _deviceservice = deviceservice; if(_deviceservice.modulefolders.count>0) { selecteditem = _deviceservice.modulefolders[0]; } }
viewmodel of module b
in viewmodel of module b eventaggregator subscribte event.
#region private fields ************************************************************************************************** private modulefolder _currentfolder; private readonly ieventaggregator _eventaggregator; private readonly ideviceservice _deviceservice; private readonly iuidispatcher _uidispatcher; private observablecollection<moduleviewmodel> _observablemodules; private moduleviewmodel _selectedlistitem; #endregion #region public properties *********************************************************************************************** public observablecollection<moduleviewmodel> observablemodules { { return (_observablemodules); } set { _observablemodules = value; onpropertychanged(() => observablemodules); } } public moduleviewmodel selectedlistitem { { return _selectedlistitem; } set { _selectedlistitem = value; onpropertychanged(() => selectedlistitem); } } #endregion #region constructor(s) ************************************************************************************************** public modulelistviewmodel(ieventaggregator eventaggregator, iuidispatcher uidispatcher, ideviceservice deviceservice) { modulefolderchangeevent evt = eventaggregator.getevent<modulefolderchangeevent>(); evt.subscribe(onmailfolderchanged); _eventaggregator = eventaggregator; _uidispatcher = uidispatcher; _deviceservice = deviceservice; propertychanged += modulelistselectionviewmodel_propertychanged; } #endregion
bootstrapper
in bootsrapper module depends on modul b.
protected override void configuremodulecatalog() { base.configuremodulecatalog(); modulecatalog modulecatalog = (modulecatalog) modulecatalog; //communication type servicemodule = typeof(communicationmodule); modulecatalog.addmodule(servicemodule); //device list type devicelistuimodule = typeof(devicelistmodule); system.collections.objectmodel.collection<string> dependsdevicelistui = new system.collections.objectmodel.collection<string> { servicemodule.name }; modulecatalog.addmodule(new moduleinfo { modulename = devicelistuimodule.name, moduletype = devicelistuimodule.assemblyqualifiedname, dependson = dependsdevicelistui, }); //tap region type selectionuimodule = typeof (selectionmodule); system.collections.objectmodel.collection<string> dependsselectionui = new system.collections.objectmodel.collection<string> { servicemodule.name, devicelistuimodule.name }; modulecatalog.addmodule(new moduleinfo { modulename = selectionuimodule.name, moduletype = selectionuimodule.assemblyqualifiedname, dependson = dependsselectionui }); }
the problem
when module loaded. first item selected , publish event. module b not loaded subscribe late event miss first publish. @ second time when module b loaded every thing works fine.
i have read how control order of module initialization in prism. maybe there way or better way of doing that. because i'm new in prism , dont best way doing it.
sorry poor english. :-(
within bootstrap process ensure "moduleb" gets loaded , initialized before "modulea".
Comments
Post a Comment