c# - Caliburn.Micro assign resolved ViewModel instance to child from parent -


controls:tabcontrolview reusable component. need able create viewmodel/retrieve instance each component usage.

<usercontrol x:class="app.views.shell.shellview" ...>     <stackpanel orientation="vertical">          <controls:tabcontrolview cal:bind.model="{binding tabcontrolviewmodel}"/>      </stackpanel> </usercontrol> 

in shellviewmodel constructor:

public tabcontrolviewmodel tabcontrolviewmodel { get; set; } public shellviewmodel(){     tabcontrolviewmodel = new tabcontrolviewmodel();//for simplicity. resolved ioc } 

when put break point tabcontrolviewmodel's constructor can see being called 2 times.

when setup ioc resolve tabcontrolviewmodel singleton works (as internal call resolving tabcontrolviewmodel served same instance).

how should edit code doesn't call bootstrapperbase.getinstance() automatically or how can replace view's viewmodel?

i found out viewmodel resolved caliburn automatically injected property:

public tabcontrolviewmodel tabcontrolviewmodel { get; set; } 

all needed make propfull , setup of handed instance there:

private tabcontrolviewmodel _tabcontrolviewmodel;  public tabcontrolviewmodel tabcontrolviewmodel {     { return _tabcontrolviewmodel; }     set     {         _tabcontrolviewmodel = value;         //init here         notifyofpropertychange(() => tabcontrolviewmodel);     } } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -