c# - Caliburn.Micro rebind ContentControl on navigation GoBack -


i'm using caliburn.micro within winrt application

here main vm:

public class mainviewmodel : conductor<screen> {     protected override void onactivate()     {         if (activeitem == null)         {            activateitem(                viewmodellocator.locateforviewtype(typeof(newsfeedview)) screen);         }          base.onactivate();     } } 

here use conductor because want load different controls in contentcontrol, have code. here content control in main view:

<contentcontrol x:name="activeitem" grid.column="1" grid.row="1" /> 

when running application work fine, mainviewmodel.activate gets called , activeitem set newsfeedviewmodel , contentcontrol loads newsfeedview.

the problem:

when navigate in newsfeedview control view using navigationservice.navigatetoviewmodel method , in view use navigationservice.goback, i'm returning mainview , in moment when mainviewmodel.activate gets called activeitem not null, contentcontrol.content null. i've tried use view.model attached property contentcontrol no luck, how make rebind?

edit: i'm setup logger in caliburn see happens , found error - when mainview loaded after navigationg events occuring:

attaching ***.views.mainview ***.viewmodels.mainviewmodel. viewmodel bound on activeitem. using cached view ***.viewmodels.newsfeedviewmodel. system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> system.exception: unspecified error @ windows.ui.xaml.controls.contentcontrol.put_content(object value) ... winrt stack @ caliburn.micro.view.setcontentpropertycore(... 

though not informative i've used intelitrace more info , got message: "element child of element". suppose newsfeedview stored somewhere , when time comes put in contentcontrol exception thrown. how solve this?

you should adopt view model first approach. in other words, activate instance of view model, , caliburn.micro view location , binding you.

it looks want instantiate view model once in constructor example, or oninitialise:

public mainviewmodel() {     this.activateitem(new newsfeedviewmodel()); } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -