silverlight - How do you refresh your ViewModel when navigating back using MVVM -
when navigating using button on phone how can refresh viewmodel?
i'm using button on phone believe same calling navigationservice.goback(), navigates previous page on stack constructor not called in view or viewmodel.
you can hook in base page class onnavigatingto event , call method on viewmodel. don't have vs me pseudo-code be:
in mybasepage : page
public void onnavigatingto(object sender, eventargs e) { var vm = this.datacontext baseviewmodel; if(vm != null) { vm.initialize(); } }
you can same before leaving page:
public void onnavigatingfrom(object sender, eventargs e) { var vm = this.datacontext baseviewmodel; if(vm != null) { vm.save(); } }
Comments
Post a Comment