silverlight - Prism MVVM - How to pass an IEventAggregator to my ViewModel -


recently started working prism in silverlight. want use eventaggregator subscribe , publish events between 2 viewmodels. saw on guides, viewmodel's ctor should accept ieventaggregator parameter. can't find out how hence view wants initialize viewmodel parameterless ctor.

my viewmodel ctor:

myviewmodel(ieventaggregator eventaggregator) {     // event.... } 

my view:

<usercontrol ....>      <usercontrol.resources>         <viewmodels:myviewmodel x:key="myviewmodel"/>     </usercontrol.resources>      <grid x:name="layoutroot" datacontext="{binding source={staticresource myviewmodel}}">     ....     <grid/>  </usercontrol> 

i can instantiate viewmodel in ctor of view, , assign datacontext, must have ieventaggregator in view, cannot get. not correct way pass ieventaggregator (or other object! - iunitycontainer example) viewmodel.

can tell me i'm doing wrong?

you have resolve dependency via unity. have @ prism mvvm examples , ui composition. there view not create view model, other way round. view model gets view injected via constructor injection. view model sets view model view:

public interface iview {     iviewmodel viewmodel{get;set;} }  public interface iviewmodel { }  public view:usercontrol, iview {     public iviewmodel viewmodel     {         get{return datacontext iviewmodel;}         set{datacontext = value;}     } }  public viewmodel:iviewmodel {     public viewmodel(iview view, ieventaggregator eventaggregator)     {         view.viewmodel = this;         //get event...     } } 

using approach have register view model , view unity. afterwards have resolve view model, view injected container.

to view right place on user interface have register view region using regionmanager. when set up, creating new view model instance results in adding view registered region shows on user interface.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -